How to implement rest message integration from script after generating token from get oauth token ui action

vidit7
Mega Contributor

Hi All,

I have a requirement to integrate servicenow with a third party tool. So I am using REST with OAuth 2.0 authentication with grant type is resource owner password credentials(password) while implementing it.

Now what I did to implement is =

1. I have made a record in Oauth registry

2. Then created a new rest outbound and selected authentication type as Oauth 2.0 and selected desired oauth profile.

3. Now clicked on get OAuth token and it is asking me to input the user name and password, after filling user name and password, OAuth token is successfully generated.

4. After that i have tested my POST message and got the desired result.

Now the thing is I have to implement the same in script like in business rule or workflow script. So In case of basic authentication, we just call the rest message and get the desired output. In case of Oauth, the token expire in some 30 mins. So after that we are not manually click on get oauth token again and again to generate the token. So I found a script to generate the token and want to use the same token in the rest message to get the output from script.

Can any one of you tell me how to use the token while calling the rest post message if token is not generated from get OAuth token.

Please tell me the process , how to do it?

Thanks & Regards,

Vidit

josh.nerius Please comment.

12 REPLIES 12

Harsh Vardhan
Giga Patron

Hi harsh,



I have gone through this blog many times and saw a lot more video but still it is not done.


Actually in above thread the thing i am asking is not mentioned. If you have any idea the please do tell me.



Thanks,


Vidit


if i am not wrong you have an issue with the token. how to use token based Oauth in the script?


Please correct me if i did not understand correctly.


Hi Harsh,



I have successfully generated the token and got the desired response using that token in post message. But this I did in Rest outbound module itself. I want to do it from script.


Like in Rest outbound if i generate the token by clicking on getoauthtoken then it will generate the new token and then i call my rest message from my script. But after half an hour when this token expires then my rest message won't work. Right ?


So I am planning to generate the token from script and want to use the same in my rest message function via passing that token as parameter or variable or something like this.



Help is appreciated.



Thanks,


Vidit