Scheduled job to automatically get new Oauth token/refresh token when old one expires

Andrei Radules1
Giga Contributor

Hello,

I currently have 2 ServiceNow Instances synced between each other using OAuth 2.

Currently, when the token expires I have to manually get a new one from the REST message.

I am trying to create a new Scheduled job to run just before the refresh token expires so I can create a new one automatically without any manual input.

Can someone advise how the scheduled job script will look so that it checks for an expiry date of the current token and then automatically requests and updates the new token?

Thank you!

 

6 REPLIES 6

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

I don't think this is required. the code where you are actually making an API call just before that have a script to get the access token again and then use that.

Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

I am trying to not include the token request directly in the  business rules

Hi @Ankur Bawiskar 

1. Can you tell exactly needs to be scripted? 
2. For the first time to get access token, do we need to do it manually by clicking"get access token"?

Thanks,

Shraddha

 

@SN developer 

Can you post a new question for this and tag me there

This is quite older thread.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader