Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Securing Credentials used in ScriptedRestAPI

Jamshaid
Tera Contributor

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.


 
2023-10-27_11-04.png

 

 

How do I refer to this in my code? I am not finding the way in the referenced article. 

 

0 REPLIES 0