Suitescript code for OAuth authorization requests to Salesforce for fetching access token

let endPoint = 'https://hostname/services/oauth2/token';
let requestBody = {
    'client_id': { client_id },
    'client_secret': { client_secret },
    'username': { username },
    'password': { password },
    'grant_type': 'password'
};
let salesRequest = https.post({
    url: endPoint,
    headers: {
        'Content-Type': 'application/x-www-form-urlencoded',
    },
    body: Object.keys(requestBody).map(key => key + '=' + encodeURIComponent(requestBody[key])).join('&')
});
let responseBody = JSON.parse(salesRequest.body);

Leave a comment

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