How to get oAuth token automatically once it expires through script

Siddharth5
Kilo Contributor

Hi All,

I am trying to get the Oauth token from Zoho API. Below is the background script I used to get the Access token and refresh token but I need to get the authorisation code to proceed further.

How to get the authorization code:

var oAuthClient = new GlideOAuthClient();
var params = {
'grant_type': "authorization_code",
redirect_uri: '<instance_name>',
'scope': '<>',
'code': '<>'
};
var json = new JSON();
var text = json.encode(params);
var tokenResponse = oAuthClient.requestToken('<>', text);
gs.info("Error:" + tokenResponse.getErrorMessage());

var token = tokenResponse.getToken();
gs.log("AccessToken:" + token.getAccessToken());
gs.log("AccessTokenExpiresIn:" + token.getExpiresIn());
gs.log(" RefreshToken:" + token.getRefreshToken());

How to get the authorization code. and where to use the above script to get these codes continously. It's quite urgent seeking help from this.

Thanks,

Sid.

1 REPLY 1

Sulabh Garg
Mega Sage
Mega Sage

Hello Siddharth,

Please check below link

How to update Refresh token automatically once it expires in oauth2

How to generate the access token once it is expired from Business Rule?

 

Please Mark ✅ Correct/helpful, if applicable, Thanks!! 

Regards

Sulabh Garg

Please Mark ✅ Correct/helpful, if applicable, Thanks!!
Regards
Sulabh Garg