0

(function process(/*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
var httpClient = new sn_ws.RESTMessageV2();
httpClient.setHttpMethod('post');
httpClient.setEndpoint('https://your-oauth-server.com/token');
httpClient.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
httpClient.setRequestBody('grant_type=client_credentials&client_id=your-client-id&client_secret=your-client-secret');
var httpResponse = httpClient.execute();
var httpResponseStatus = httpResponse.getStatusCode();
var httpResponseContentType = httpResponse.getHeader('Content-Type');
var httpResponseObj = JSON.parse(httpResponse.getBody());
gs.print(httpResponseObj.access_token)
})(request, response);

Oauth 2.0 token request header parameters to get access token API ServiceNow
Working Code Asked question August 26, 2024