- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-15-2017 10:18 AM
I simply want to send a POST message to a server. I have a GET working from that same server already on SNOW.
I just can't figure out how to send the request body.
For instance I want to mimic this curl statement
curl -H "Content-Type: application/json" -X POST -d '{"title":"hi"}' http://live_server:5000/api/v1/incident
Where do I enter the {"title":"hi"}?
This image shows the UI that I am dealing with, it looks different from the tutorial UI's so I am having trouble using them.
I cannot find the Request Body field
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-15-2017 01:53 PM
You need to send a string in the request body.
Change these two...
var body = {"title":"hi"};
r.setRequestBody(body);
To this:
var body = '{"title":"hi"}';
r.setRequestBody(body);
or
var body = {"title":"hi"};
var bodyText = JSON.stringify(body);
r.setRequestBody(bodyText);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-15-2017 10:29 AM
Hi Matthew,
You'll have to call this REST message via script. Once you set up the sn_ws.RESTMessageV2() object, use the setRequestBody() method with the stringified JSON object you want to pass.
https://developer.servicenow.com/app.do#!/api_doc?v=jakarta&id=r_RMV2-setRequestBody_String_body
Lots of good examples on Live Coding Happy Hour.
ServiceNow Dev Program - YouTube

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-15-2017 11:47 AM
Let me know if I have answered your question or if there is still something you need on this one.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-15-2017 12:05 PM
Right now I have a business rule that calls the outbound rest service which can see in my picture above.
The Business rule's code is below and the condition is set as blank.
I can call this business rule and see the message sent by the business rule.
But I cannot see this code's output and the server does not seem to have received the POST successfully.
Can you see an issue with my code? If not, how do I debug?
try {
var r = new sn_ws.RESTMessageV2('Flask speaker', 'new ticket');
//override authentication profile
//authentication type ='basic'/ 'oauth2'
//r.setAuthentication(authentication type, profile name);
// curl -i -H "Content-Type: application/json" -X POST -d '{"title":"hi"}' http://my_server.net/api/v1/incident
var body = {"title":"hi"};
r.setRequestBody(body);
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
}
catch(ex) {
var message = ex.getMessage();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-15-2017 12:34 PM
For some more context on my intent here is a question that I asked earlier: send POST request when a business rule is activated