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][1]
that explains storing credentials in ServiceNow. I have stored the API Key credentials but have not found a way to use them 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 or anywhere else.