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

if you want to use cURL you can try to have look in rest API explorer .



curl.png


here you will see the syntax. if you run any method here and check the sample code in cURL it will show some script here



curl.png


Hi Harsh,



Can we use this curl script in business rule or in back ground script.??



Thanks,


Vidit