Example of a Suitelet that Calls a RESTlet
Here’s an example of how a Suitelet can call a RESTlet.Since the Suitelet’s in the same NetSuite account as the RESTlet, the script can use the N/url module to find the RESTlet’s URL. For this approach, you’ll need the script ID and script deployment ID for the RESTlet.
Note:
The scriptId, deploymentId, and authorization info here are just placeholders—make sure to swap them out with the real values from your NetSuite account before using the script.
/**
* @NApiVersion 2.x
* @NScriptType Suitelet
*/
define(['N/https', 'N/url'], function(https, urlMod) {
return {
onRequest : function(options) {
var url = urlMod.resolveScript({
scriptId: 'customscript196',
deploymentId: 'customdeploy1',
returnExternalUrl: true,
params: {parametername: 'value'}
});
var headers = {'Authorization': 'NLAuth nlauth_account=12345, nlauth_email=john@smith.com, nlauth_signature=Welcome123, nlauth_role=3'};
var response = https.get({url: url, headers: headers});
options.response.write(response.body);
}
};
});
Related Topics
- SuiteScript 2.x RESTlet Script and Request Examples
- Example Hello World RESTlet
- Example of a RESTlet that Retrieves, Deletes, Creates, and Upserts a NetSuite Record
- Example of a RESTlet that Adds Multiple Records
- Example of a RESTlet that Manipulates Scheduled Script
- Example of a Client Script that Calls a RESTlet
- Example of a Shell Script that Calls a RESTlet