The N/https module is one of the most essential components in SuiteScript. Whether you’re integrating NetSuite with an external API, sending JSON payloads, retrieving data, or automating workflows between platforms, the N/https module is the backbone of most HTTP-based integrations.
In this blog, we break down:
- What the N/https module does
- Supported HTTP methods
- How to send GET, POST, PUT, DELETE, and custom requests
- Headers, authentication, and payload handling
- When to use N/https vs N/https/clientCertificate
- Best practices and security tips
- Example SuiteScript code for common integrations
Let’s get into it.
⭐ 1. What Is the N/https Module?
The N/https module allows SuiteScript to make standard HTTP and HTTPS requests to external servers. It supports:
✔ REST APIs
✔ JSON/XML data exchanges
✔ Webhooks
✔ Token-based authentication
✔ Basic authentication
✔ Custom headers
✔ Sending & receiving HTTPS traffic
It is the most widely used module for NetSuite API integrations.
If you need to call any external service — from Shopify to Salesforce to internal company systems — you will almost always use N/https.
⭐ 2. Supported Methods in N/https
The module includes functions for every major HTTP method:
| Method | Usage |
|---|---|
| https.get(options) | Retrieve data |
| https.post(options) | Create new records, send data |
| https.put(options) | Update an existing resource |
| https.delete(options) | Delete a resource |
| https.request(options) | Generic HTTP request handler |
All methods return an https.ClientResponse object containing:
response.code(HTTP status)response.headersresponse.body
⭐ 3. Basic Example: HTTP GET Request
/**
* @NApiVersion 2.1
*/
define(['N/https'], (https) => {
function getExample() {
const response = https.get({
url: 'https://api.example.com/customers/123'
});
log.debug('Status', response.code);
log.debug('Body', response.body);
}
return { execute: getExample };
});
⭐ 4. HTTP POST Example (JSON Payload)
const response = https.post({
url: 'https://api.example.com/orders',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + token
},
body: JSON.stringify({
orderId: 12345,
amount: 99.99,
status: 'Created'
})
});
log.debug('API Response', response.body);
⭐ 5. PUT Request Example
const response = https.put({
url: 'https://api.example.com/orders/12345',
body: JSON.stringify({ status: 'Shipped' }),
headers: { 'Content-Type': 'application/json' }
});
⭐ 6. DELETE Request Example
https.delete({
url: 'https://api.example.com/orders/12345',
headers: {
'Authorization': 'Bearer ' + token
}
});
⭐ 7. Using https.request() for Custom Methods
If the API uses unusual HTTP methods (PATCH, OPTIONS, HEAD):
https.request({
method: https.Method.PATCH,
url: 'https://api.example.com/items/1',
body: JSON.stringify({ price: 29.99 })
});
⭐ 8. Handling API Authentication
N/https supports multiple authentication types:
✔ API Key Authentication
headers: { 'x-api-key': '123456' }
✔ Bearer Token Authentication (OAuth 2.0)
headers: { 'Authorization': 'Bearer ' + token }
✔ Basic Authentication
headers: {
'Authorization': 'Basic ' + encode.convert({
string: username + ':' + password,
inputEncoding: encode.Encoding.UTF_8,
outputEncoding: encode.Encoding.BASE_64
})
}
✔ OAuth 1.0 (Manually generated)
Used in some legacy APIs.
⭐ 9. N/https vs N/https/clientCertificate — When to Use Which
Use N/https when the API requires:
✔ Bearer tokens
✔ Basic auth
✔ API keys
✔ JSON/XML payloads
✔ Standard HTTPS
Use N/https/clientCertificate when the API requires:
✔ SSL client certificate authentication
✔ Mutual TLS
✔ Bank-level secure channels
✔ Private certificate-based APIs
Most APIs only need N/https.
⭐ 10. Error Handling & Troubleshooting
Wrap API calls in try/catch blocks:
try {
const response = https.get({ url });
if (response.code >= 400) {
log.error('API Error', response.body);
}
} catch (e) {
log.error('Request Failed', e);
}
⭐ 11. Best Practices for Using N/https
✔ Always set proper timeouts
Slow APIs may freeze scripts.
✔ Do not log sensitive data
Avoid logging tokens or personal info.
✔ Keep payloads small
Large data sets should be chunked.
✔ Use REST services efficiently
Cache tokens and avoid unnecessary calls.
✔ Test with mock APIs before going live
Helps prevent accidental production data modification.
✔ Validate API responses
Never assume API data is always correct.
⭐ 12. Common Real-World Uses of N/https in Integrations
- Shopify → NetSuite order sync
- Salesforce → NetSuite contact sync
- Amazon Marketplace API calls
- Payment gateways (Stripe, PayPal, Moneris)
- WMS or 3PL integration
- Sending fulfillment updates to external partners
- Retrieving product pricing or inventory
If it’s a REST API, N/https can handle it.
⭐ 13. Final Thoughts
The N/https module is one of the most important tools in every NetSuite developer’s toolbox. From simple GET requests to complex OAuth 2.0 integrations, it powers almost every modern integration.
By understanding the methods, authentication patterns, and best practices, you can build:
- reliable
- scalable
- secure
API connections directly inside SuiteScript.
If you’re integrating NetSuite with external systems, this module is indispensable.
Discover more from The NetSuite Pro
Subscribe to get the latest posts sent to your email.
Leave a Reply