N/http Module Script Samples
Explore N/http module script samples, including HTTP GET requests and redirecting records in SuiteScript 2.1.
The N/http module in SuiteScript provides developers with the ability to handle HTTP requests effectively. This article illustrates two practical examples of using the N/http module, including how to make GET requests and redirect records within the NetSuite environment.
How to Request a URL Using HTTP GET
In SuiteScript, you can perform an HTTP GET request to retrieve data from a specified URL. The following sample demonstrates how to execute a GET request using the N/http module:
Code Sample: HTTP GET Request
1/**2 * @NApiVersion 2.13 */4// This script uses an HTTP GET request for a URL.5require(['N/http'], (http) => {6 function sendGetRequest() {7 let response = http.get({8 url: 'http://www.google.com'9 });10 // Process the response11 log.debug({ title: 'Response', details: response.body });12 }13 sendGetRequest();14});Important Notes:
- Make sure to replace the URL with the desired endpoint you wish to request data from.
- The sample script is designed for use in the SuiteScript Debugger. For production deployment, adapt it appropriately based on the script type requirements.
How to Redirect a Record
Another useful feature of the N/http module is the ability to redirect users to a specific record within NetSuite. This example shows how to create a Suitelet that redirects to a new sales order record while setting an entity field.
Code Sample: Redirecting to a Sales Order Record
1/**2 * @NApiVersion 2.13 * @NScriptType Suitelet4 */5// This script redirects to a new sales order record and sets the entity.6define(['N/record', 'N/http'], (record, http) => {7 function onRequest(context) {8 context.response.sendRedirect({9 type: http.RedirectType.RECORD,10 identifier: record.Type.SALES_ORDER,11 parameters: ({12 entity: 6 // Ensure this is a valid entity ID13 })14 });15 }16 return {17 onRequest: onRequest18 };19});Important Notes:
- Ensure the
entityfield is populated with a valid internal ID from your NetSuite account to avoid errors during execution. - This sample script must be used in a deployed Suitelet environment.
Key Takeaways
- The N/http module facilitates HTTP communication within SuiteScript.
- Use the provided samples to handle GET requests and redirects effectively.
- Always validate IDs when passing parameters to avoid runtime errors.
Source: This article is based on Oracle's official NetSuite documentation.
Frequently Asked Questions (4)
Do I need special permissions to perform HTTP GET requests using the N/http module in SuiteScript?
Can I use the HTTP GET request code sample in a production environment without modification?
What is a crucial step when redirecting to a sales order record using the Suitelet sample?
Does the article mention a feature flag that must be enabled to use the N/http module?
Was this article helpful?
More in SuiteScript
- SuiteScript 2.1 Enhancements in NetSuite February Updates
SuiteScript 2.1 now supports async features and PATCH method. Discover the latest API and SuiteProcurement improvements.
- Custom Tool Script Enhancements in NetSuite
Custom tool scripts in NetSuite gain execution log support and a new management page in February 16, 2026.
- Scheduling Map/Reduce Script Deployments in NetSuite
Learn to schedule map/reduce script submissions, including one-time and recurring options in NetSuite.
- API Governance Units Calculation in NetSuite 2026.1
NetSuite 2026.1 introduces examples illustrating API governance unit calculations for both user event and scheduled scripts.
