• SuiteScript 1
o nlapirequestURL()
• SuiteScript 2
o N/http: request(), get(), post(), put(), delete()
o N/https: request(), get(), post(), put(), delete()
For example, you want to make a request to Googleapis as follows:
https.get({
url: "https://maps.googleapis.com/maps/api/geocode/json?key={CUSTSECRET_GOOGLEAPIS_KEY}&address=" + encodeURIComponent(address)
});
In an unauthenticated client-side context, such calls are forbidden and need to be moved to server scripting; to achieve this, put the request into a Suitelet. This ensures the request is performed safely in a server environment.
/**
* Geocode Search
*
* @NApiVersion 2.x
* @NScriptType Suitelet
*/
define([], function()
{
function onRequest(context)
{
var address = context.request.parameters["address"];
var response = https.get({
url: "https://maps.googleapis.com/maps/api/geocode/json?key={CUSTSECRET_GOOGLEAPIS_KEY}&address=" + encodeURIComponent(address)
});
// ...
// ... additional postprocessing / error handling if needed
// ...
context.response.write(response.body);
}
return {
onRequest: onRequest
};
});
On the script deployment for the Suitelet:
• Check the Available Without Login box.
• On the Audience subtab, check Select All next to the Roles field.
Now, you can perform your HTTPs request by calling the Suitelet.
https.requestSuitelet({
scriptId: "custscript_<...>",
deploymentId: "custdeploy_<...>",
external: true,
urlParams: {
address: address
}
});