Concatenate API Secrets with Strings

The following sample shows how to concatenate a string value to use as an API secret. API Secrets are string values that cannot be concatenated directly. In some cases, a code-generated string (for example, date stamp, account ID, sequence numbers) needs to be merged with the API secret. To merge the values, the N/https module must be imported on the script file and use the createSecureString() API to initialize both secret API values and ordinary string.

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 appendSecureString to concatenate strings to use as an API secret.
require(['N/https', 'N/runtime'], (https, runtime) => {
    function concatToCreateSecureString() {
        let baseUrl = https.createSecureString({
            input: 'www.someurl.com/add?apikey='
         });
        let apiKey = https.createSecureString({
            input: '{CUSTSECRET_SOME_INTEGRATION}'
        });
        let url = baseUrl.appendSecureString({
            secureString: apiKey
        });
    }
    concatToCreateSecureString();
}); 

        

General Notices