Example of a Suitelet that Calls a RESTlet
The following example shows how a Suitelet can call a RESTlet. Because the Suitelet is deployed in the same NetSuite account as the RESTlet, the script can use the N/url module to resolve the URL for the RESTlet. With this approach, you need the script ID and the script deployment ID associated with the RESTlet.
Note:
The scriptId, deploymentId, and authorization data in this example are placeholders. Before using this script, replace these values with valid data from your NetSuite account.
/**
* @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