How to encode a text to Base 64

NetSuite provides a standard encode module that can be used to encode a value or text to base 64.

Example: Creation of basic authentication string in API call

// Replace these with your actual username and password
var username = 'your_username';
var password = 'your_password';


// Create the basic auth string
var authString = username + ':' + password;
var encodedAuthString = encode.convert({
    string: authString,
    inputEncoding: encode.Encoding.UTF_8,
    outputEncoding: encode.Encoding.BASE_64
});


var headers = {
    'Authorization': 'Basic ' + encodedAuthString
};

Leave a comment

Your email address will not be published. Required fields are marked *