Securing Credentials used in ScriptedRestAPI
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-26-2023 11:04 PM
I have written a script that works using scripted rest API. It uses a Bearer token to authenticate the requests but is hardcoded in the code. It is not a good practice to hardcode a token. I went through this article that explains storing credentials in ServiceNow. I have stored the API Key credentials but, not finding a way to use it in my script. Here is my request that exists in the script.
var authToken = "Bearer token";
var restMessage = new sn_ws.RESTMessageV2();
restMessage.setHttpMethod("GET");
restMessage.setEndpoint(url);
restMessage.setRequestHeader("x-api-ppm-client", "servicenow");
restMessage.setRequestHeader("Authorization", authToken);
restMessage.setRequestHeader("Accept", "application/json");
restMessage.setRequestHeader("Content-Type", "application/json");
Here is how the key is stored.
How do I refer to this in my code? I am not finding the way in the referenced article.
0 REPLIES 0