
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-05-2019 07:59 PM
Hello,
I am new to REST API, and I have this requirement to call an outbound rest API in servicenow when a catalog is being submitted. The idea is when a user fills out the form in servicenow and submits it, it will call an api to POST/GET something in the 3rd party tool. Is this possible? Thanks in advance.
Regards,
Raphael
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-05-2019 09:19 PM
Hi Raphael,
Here is a sample script. Let me know if you need any modifications. Also, I added comments for your understanding
var request = new sn_ws.RESTMessageV2();
request.setEndpoint('ENDPOINT of thord party tool');
request.setHttpMethod('POST'); //mention here POST or GET
/*Use one of the below statement to set authentication*/
//request.setBasicAuth(user,password);
request.setRequestHeader('Authorization','Basic SU5UTFxBNjEzNjIzOklORllAMTAwOA==');
//Set here how you are sending the data i.e. XML or JSON
request.setRequestHeader("Accept","application/xml");
request.setRequestHeader('Content-Type','application/xml');
request.setRequestBody('Give the body here to send');
request.setMIDServer('MIDSERVER'); //Set Mid server if you are using any
var response = request.execute(); //It will send the post request to thord party tool
//Use below code to check response
//response.waitForResponse(50);
//response.setHttpTimeout(10000);
var responseBody = response.getBody(); //this now holds the XML inside the envelope, as a string
var xmlDoc = new XMLDocument2();
xmlDoc.parseXML(responseBody);
var val = xmlDoc.getNodeText('/ID');
Please mark this comment as Correct Answer/Helpful if it helped you.
Cheers,
Hardit Singh

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-05-2019 09:38 PM
Thanks for this. When declaring the endpoint, should it be the link to the third party tool?
Is this where I can declare what variable values will I send?
request.setRequestBody('Give the body here to send');
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-05-2019 09:45 PM
Yes, in the endpoint the link which third party tool has provided.
In the request body you will give what values you have to send. Ex. if you want to send values in JSON
{"short_description":"TEST","category":"CategoryTest"}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-05-2019 09:49 PM
What if I want to assign values dynamically in the request body? Can I use current.short_description for example