- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago - last edited 3 weeks ago
Hi all,
i have started exploring Integrations.
How to set access token stored in system properites in to Http request please guide me in detail.
i have tried hardcode value in bearer its working i want them dynamically.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hope you are doing good.
Did my reply answer your question?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
*** My response was accepted as a solution but for some odd reason it got removed from the thread. See attached snip from email. Posting the dynamic solution requested for future reference. ***
Here are the step by step guide on how you integrate with external application or even ServiceNow instance.
1) First create one "OAuth Provider" record in Application Registry as shown below. Ensure to get the relevant info from 3rd party app, like you are integrating with https://webexapis.com.
Details you would need :
a) Client ID
b) Secret
c) Authorization URL - (Get authorization URL from webex docs. It will have something similar as shown in snip below)
d) Token URL - (Similarly get Token URL from webex docs. It will have something similar as shown in snip below)
Redirect URL will be your ServiceNow URL as shown in the snip below. It gets auto populated. Don't change it. Rest of the fields are defaults, leave them as they are. Above 4 details are enough to start.
One last thing, as soon as you save the "OAuth Provider" record in Application Registry, it will automatically create one "Default OAuth Entity Profile". This record will be used in REST Message to call the "OAuth Provider" record in Application Registry to trigger your OAuth and generate your token. See step 2.
2) Create a REST Message record and add the details as mentioned for example. Replace with your 3rd party app URL. https://webexapis.com/v1/message
3) Next, save the record and click on "Get OAuth Token" in the related link. It will show you the Pop Up window to Authenticate first time as you don't have your Access Token and Refresh Token yet. (Mentioned in the REST Message record info message on top).
4) You would need a "User Name" and "Password" from webex with right API permissions assigned to it to get you first Access Token and Refresh Token and click on "Get OAuth Token". If all goes well you will see a successful message in green and Access Token/Refresh Token will get saved in Manage Token table.
You should NEVER create any Property to save these Tokens, Client ID's and Secrets because ServiceNow has already created the required feature and functionalities to assist you with these things with low code and secure your platform with right security posture.
After the Tokens are granted they will live in Manage Token table. Like example below.
And finally your script will look like below. Change or adjust variables as per your use case. I am just pasting the example script.
try {
var r = new sn_ws.RESTMessageV2('GetUiPathData', 'Default GET');
//override authentication profile
var authentication_type = 'oauth2';
r.setAuthenticationProfile(authentication_type, "125ce63ce4001410f877ce457cda6b55"); // SysID of your OAuth Entity Profile
//set a MID server name if one wants to run the message on MID
//r.setMIDServer('MY_MID_SERVER');
//if the message is configured to communicate through ECC queue, either
//by setting a MID server or calling executeAsync, one needs to set skip_sensor
//to true. Otherwise, one may get an intermittent error that the response body is null
//r.setEccParameter('skip_sensor', true);
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
gs.info("httpStatus : " + httpStatus);
} catch (ex) {
var message = ex.message;
}
You can get this script from the related method records related link called "Preview Script Usage". See snip below.
Status Code 200 meaning we are good to proceed with other methods to either GET any other info from that API or POST/PATCH/PUT/DELETE as per use case and access provided on that API.
Cheers and enjoy Integration!
Hope this helps.
Regards,
Vikas K