Generate a Secure Token and a Secret Key

The following sample shows how to use a GUID to generate a secure token and a secret key. To run this sample in the debugger, you must replace the GUID with one specific to your account.

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.x Script Basics and SuiteScript 2.x Script Types.

Important:

This sample uses SuiteScript 2.1. For more information, see SuiteScript 2.1.

          /**
 * @NApiVersion 2.1
 */

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

        

General Notices