Calling an Outgoing REST API from a Service Now workflow
The magic link between Service Now workflows and API calls are Run Scripts. In this article we will go over this so you can make those outgoing API calls you have already built in Service Now (see this article about that).
To create your call to your API do the following:
- Checkout your workflow
- Right click anywhere on the workflow and click “Add Core Activity”

3. Next take select the “Run script definition

4. Create your run script. Below is a sample of what it looks like. This is a super basic call, but you get the idea here. The magic part of this is declaring an object that is a Rest Message and setting the parameters. The rest is history.

Code Block for this example is here:
try {
var r = new sn_ws.RESTMessageV2('myRestOutboundCall', 'NameOfHttpMethod');
r.setStringParameterNoEscape('MyVariableSubstitution', current.variables.varFromForm );
r.setStringParameterNoEscape('MyVariableSubstitution2', current.variables.second_varFromForm );
var varExecute = r.execute();
}
catch(ex) {
var message = ex.message;
}
workflow.info("Some Debug Message of the logs - Running REST API call:" + " Value for MyVariableSubstitution: " + current.variables.varFromForm + ", My second var MyVariableSubstitution2: " + current.variables.second_varFromForm );
Ben Tuma
Over 20 years of experience in the Information Technology field. I love technology and seeing how it changes and impacts peoples lives for the better. I have healthy appetite for innovation and problem solving.
I am sharing my knowledge and challenges in hopes to help others as we constantly face ever changes problems in IT and technology.