Not able to use the Access Token generated from the Salesforce OAuth profile for the REST call

pro-test
Tera Contributor

Hello Helpers,

 

I'm doing an integration from ServiceNow to Salesforce. I was able to generate the access token from the script but was not able to use it for the REST call. I'm using the Authorization code flow for this integration. I'm using the below code to generate the access token:

var clientRequest = new sn_auth.GlideOAuthClientRequest();
clientRequest.setGrantType('refresh_token');
clientRequest.setRefreshToken('<<refresh token>>');
//GlideOAuthClient
var client = new sn_auth.GlideOAuthClient();
//GlideOAuthClientResponse
var tokenResponse = client.requestTokenByRequest('<<rest message>>', clientRequest);
//GlideOAuthToken
var token = tokenResponse.getToken();
var accessToken = token.getAccessToken()

After receiving the access token, I'm not able to use it in the script to make the REST call. I tried using multiple ways to pass access token in the header but no luck.

Can you please help to achieve the same?

 

Thank You in advance!

WR//Proneet

 

 

 

5 REPLIES 5

Hi Amit, I'm able to get the access tokens but I'm not able to use them in my script. I'm trying passing it as a header but no luck

 

WR//Proneet