π§© Custom Dashboard Portlets with External Data Integration (REST & API Feeds)
Introduction
Imagine seeing Shopify orders, Salesforce leads, or 3PL shipment statuses directly inside your NetSuite dashboard β all updated in real time.
Thatβs the power of Custom Dashboard Portlets with external API integration.
Using SuiteScript 2.1 Portlet scripts, you can securely fetch and display external data right within NetSuite, turning it into a unified command center for your business.
π‘ Why Integrate External Data into Portlets?
Benefit | Example |
---|---|
Centralized Insights | Show Shopify orders, payments, or shipment tracking without switching apps. |
Faster Decision-Making | Display real-time sales or support data from CRMs. |
Reduced Manual Reporting | Automate dashboards that consolidate data from multiple systems. |
Enhanced User Experience | Give each role a tailored view (e.g., Marketing, Finance, Operations). |
βοΈ Key Components for Integration
Component | Description |
---|---|
SuiteScript 2.1 Portlet Script | Builds the visual dashboard component. |
External REST API | Source of data (Shopify, Salesforce, Boomi, etc.). |
N/https Module | Makes external HTTP requests. |
JSON Parsing | Converts response into readable table/chart format. |
Audience Restrictions | Controls which roles can view the portlet. |
π§± Step-by-Step: Creating an External Data Portlet
Step 1: Enable REST Integration
- Ensure Outbound HTTPS Requests are allowed.
- Verify that the external system (e.g., Shopify API) supports CORS or basic auth.
Step 2: Create the SuiteScript Portlet
/**
* @NApiVersion 2.1
* @NScriptType Portlet
*/
define(['N/https', 'N/log'], (https, log) => {
const render = (params) => {
const portlet = params.portlet;
portlet.title = 'Shopify Orders (Last 5)';
try {
// Call Shopify REST API
const response = https.get({
url: 'https://yourshop.myshopify.com/admin/api/2024-01/orders.json?limit=5',
headers: {
'X-Shopify-Access-Token': 'your_api_token_here'
}
});
const orders = JSON.parse(response.body).orders;
let html = "<table style='width:100%; border-collapse:collapse;'>";
html += "<tr style='background:#efefef'><th>Order #</th><th>Date</th><th>Total</th></tr>";
orders.forEach(order => {
html += `<tr>
<td>${order.name}</td>
<td>${order.created_at.substring(0,10)}</td>
<td>${order.total_price}</td>
</tr>`;
});
html += "</table>";
portlet.html = html;
} catch (e) {
log.error('Error Fetching API', e);
portlet.html = `<p style='color:red;'>Error loading external data: ${e.message}</p>`;
}
};
return { render };
});
β
Result:
A dynamic dashboard table that displays the latest orders from Shopify inside NetSuite.
Step 3: Deploy the Script
- Go to Customization β Scripting β Scripts β New β Portlet
- Upload the script file.
- Under Deployments, assign to roles (e.g., Sales Manager).
- Save and add portlet to your dashboard.
Step 4: Add to Dashboard
- On your Home Dashboard, click Personalize.
- Select Custom Portlet β choose your script name.
- Refresh dashboard β external data will appear in real time.
π Example: Display Salesforce Opportunities
You can use Salesforce REST API (via OAuth token) to fetch pipeline metrics:
const response = https.get({
url: 'https://yourinstance.salesforce.com/services/data/v57.0/query?q=SELECT+Name,StageName,Amount+FROM+Opportunity+LIMIT+5',
headers: { Authorization: 'Bearer your_access_token' }
});
Then parse response.body.records
and display it in your table or chart.
π Visualizing with Chart.js (Optional)
To make your portlet interactive:
portlet.html = `
<canvas id="oppChart"></canvas>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script>
new Chart(document.getElementById('oppChart'), {
type: 'bar',
data: {
labels: ['Q1','Q2','Q3','Q4'],
datasets: [{ label: 'Revenue ($)', data: [30000, 40000, 50000, 60000], backgroundColor: '#0066cc' }]
}
});
</script>
`;
β Perfect for management dashboards or KPI overviews.
π Securing External API Calls
Risk | Best Practice |
---|---|
Exposed API Tokens | Store tokens in NetSuiteβs Credential / Secret Store. |
Timeouts | Use short timeouts and fallback messages. |
Unauthorized Access | Restrict portlet audience under deployment settings. |
Rate Limits | Cache responses or limit refresh to once per hour. |
Example with caching:
if (cache.get({ key: 'shopify_data' })) {
// Use cached data
} else {
// Fetch new data and store in cache
}
π§ Advanced Use Cases
Use Case | Description |
---|---|
3PL Integration | Show real-time shipment statuses from ShipBob or UPS. |
Marketing KPIs | Display campaign metrics from Google Analytics API. |
Support Dashboard | Show Zendesk ticket summary by priority. |
Financial Overview | Pull external FX rates for currency revaluation. |
Custom Alerts | Notify users if API data crosses thresholds. |
π§© Common Issues & Fixes
Problem | Cause | Solution |
---|---|---|
SSS_REQUEST_TIME_EXCEEDED | Slow API response | Cache data or reduce API payload |
Empty portlet | Invalid JSON or authentication error | Log response and validate credentials |
Dashboard lag | Too many external calls | Limit frequency or add manual refresh button |
Unauthorized | Token expired | Refresh access token periodically |
β‘ Best Practices
β
Use N/https
for secure external communication.
β
Keep API keys encrypted using the Credential module.
β
Minimize dashboard load time β fetch only necessary data.
β
Cache responses in N/cache
to prevent repeated calls.
β
Log only summary data (not sensitive API responses).
π Related Tutorials
- π Custom Portlets in NetSuite
- π SuiteScript Security & Governance Best Practices
- π SuiteAnalytics Workbook for Dashboards
β FAQ
Q1. Can I make POST requests to APIs?
Yes β use https.post()
and include headers and body payload in JSON format.
Q2. How often can I refresh external data?
Portlets load on dashboard refresh; you can also add a βRefresh Dataβ button using JavaScript.
Q3. Can I use OAuth 2.0 with Portlets?
Yes, but you must handle token storage securely (using N/credential
).
Q4. Can I show images or charts from external APIs?
Yes, but only if the content is HTTPS and accessible publicly or through secure URLs.
π§ Summary
Custom Dashboard Portlets with external data integration bridge the gap between NetSuite and other business systems.
They empower users to see live data β from sales to logistics β without switching tabs or exporting reports.
With SuiteScript and secure REST integration, you can turn NetSuite into a unified business intelligence hub β personalized for every department and role.
Leave a Reply