N/http Module Script Samples

The following script samples demonstrate how to use the features of the N/http module.

Request a URL

Important:

This sample uses SuiteScript 2.1. For more information, see SuiteScript 2.1.

The following sample shows how to use an HTTP GET request for a URL.

Note:

This sample script uses the require function so that you can copy it into the SuiteScript Debugger and test it. You must use the define function in an entry point script (the script you attach to a script record and deploy). For more information, see SuiteScript 2.x Script Basics and SuiteScript 2.x Script Types.

Important:

This sample uses SuiteScript 2.1. For more information, see SuiteScript 2.1.

            /**
 * @NApiVersion 2.1
 */

// This script uses an HTTP GET request for a URL.
require(['N/http'], (http)=> {
    function sendGetRequest() {
        let response = http.get({
            url: 'http://www.google.com'
        });
    }
    sendGetRequest();
}); 

          

Redirect a record

Important:

This sample uses SuiteScript 2.1. For more information, see SuiteScript 2.1.

The following sample shows how to use a Suitelet to redirect to a new sales order record and set the entity field (which represents the customer).

Note:

This script sample uses the define function, which is required for an entry point script (a script you attach to a script record and deploy). You must use the require function if you want to copy the script into the SuiteScript Debugger and test it. For more information, see SuiteScript 2.x Global Objects.

Important:

The value used in this sample for the entity field is a placeholder. Before using this sample, replace the entity field value with a valid value from your NetSuite account. If you run a script with an invalid value, an error may occur.

            /**
 * @NApiVersion 2.1
 * @NScriptType Suitelet
 */

// This script redirects a new sales order record and sets the entity.
define(['N/record', 'N/http'], (record, http)=> {
    function onRequest(context) {
        context.response.sendRedirect({
            type: http.RedirectType.RECORD,
            identifier: record.Type.SALES_ORDER,
            parameters: ({
                entity: 6
            })
        });
    }
    return {
        onRequest: onRequest
    };
}); 

          

General Notices