Modules

filter

 

Objects/Functions

module (N/https)

SuiteScript 2.0

Main Examples

N/https Module
Connection: Trailer Transfer-Encoding Upgrade Via
Search NetSuite - https://system.netsuite.com/app/help/helpcenter.nl?search=N/https Module

// Code Example 1
/**
* @NApiVersion 2.x
*/

// This script uses a GUID to generte a secure token and a secret key.
require(['N/https', 'N/crypto', 'N/runtime'], function(http, https, runtime) {
function createSecureString() {
var passwordGuid = '{284CFB2D225B1D76FB94D150207E49DF}';
var secureToken = https.createSecureString({
input: passwordGuid
});
var secretKey = https.createSecretKey({
input: passwordGuid
});
secureToken = secureToken.hmac({
algorithm: crypto.HashAlg.SHA256,
key: secretKey
});
}
createSecureString();
});

// Code Example 2
/**
* @NApiVersion 2.x
* @NScriptType Suitelet
*/

// This script creates a form with a credential field.
define(['N/ui/serverWidget', 'N/https', 'N/url'], function(ui, https, url) {
function onRequest(option) {
if (option.request.method === 'GET') {
var form = ui.createForm({
title: 'Password Form'
});

var credField = form.addCredentialField({
id: 'password',
label: 'Password',
restrictToDomains: ['.app.netsuite.com'],
restrictToCurrentUser: false,
restrictToScriptIds: 'customscript_my_script'
});

credField.maxLenth = 32;

form.addSubmitButton();

option.response.writePage({
pageObject: form
});
}
else {
// Request to an existing Suitelet with credentials
var passwordGuid = option.request.parameters.password;

// Replace SCRIPTID and DEPLOYMENTID with the internal ID of the suitelet script and deployment in your account
var baseUrl = url.resolveScript({
scriptId: SCRIPTID,
deploymentId: DEPLOYMENTID,
returnExternalURL: true
});

var authUrl = baseUrl + '&pwd={' + passwordGuid + '}';

var secureStringUrl = https.createSecureString({
input: authUrl
});
var secureStringPWD = https.createSecureString({
input: '{' + passwordGuid + '}'
});
var headers = ({
'pwd': secureStringPWD
});

var response = https.post({
credentials: [passwordGuid],
url: secureStringUrl,
body: {authorization:' '+ secureStringPWD + '', data:'anything can be here'},
headers: headers
});
}
}
return {
onRequest: onRequest
};
});

//SOURCE: https://system.netsuite.com/app/help/helpcenter.nl?fid=section_4418229131.html