Create a URL and Send a Secure HTTPS Post Request to the URL

The following sample shows how to get the URL to a Suitelet and send a secure HTTPS POST request to that URL with an empty body. The server's response is also logged.

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.1 Script Basics and SuiteScript 2.1 Script Types.

Important:

The value used in this sample for the scriptId and deploymentId fields are placeholders. Before using this sample, replace the scriptId and deploymentId values with valid values from your NetSuite account. If you run a script with an invalid value, an error may occur.

          /**
 * @NApiVersion 2.1
 */

// Send an HTTPS POST to an internal Suitelet in an authenticated context.
require(['N/https', 'N/log'], (https, log) => {
    const postToSuitelet = () => {
        const script = 'customscript1';
        const deployment = 'customdeploy1';
        const parameters = '';
        try {
            const response = https.requestSuitelet({
                scriptId: script,
                deploymentId: deployment,
                method: https.Method.POST,
                body: parameters
            });
            log.debug({
                title: 'Suitelet response',
                details: response.body.toString()
            });
            return response;
        } catch (e) {
            log.error({
                title: 'Suitelet request failed',
                details: e.toString()
            });
        }
    };

    return { postToSuitelet };
}); 

        

General Notices