- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
on ‎05-03-2021 04:09 AM
1. Create a string and set all the variables to be passed in request body as the key along with value separated by an '&' as below:
var body = "grant_type=credentials&resource=https://xyz.com&type=encoded&key=pqr1t5h8&user=jhonson";
2. Create a REST Message and use the content type as "application/x-www-form-urlencoded" in the request header:
var r = new sn_ws.RESTMessageV2();
r.setEndpoint("https://abc.com");
r.setRequestHeader("Accept", "application/json");
r.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); ******important*****
r.setRequestBody(body);
r.setHttpMethod('POST');
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
- 11,945 Views
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Thanks
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Thanks, It's Worked!
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
THANKS IT HELPED ME
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
@Shubhangi Suman I am trying to set the form data (input_file) in Body of the REST API along with attachment, How can I do that ? I am using r.setRequestBodyFromAttachment(<attachment sys id>) method to send the attachment.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
@Shubhangi Suman How can I set the form-data in outbound REST message body ? 'input_file' parameter should be there in REST message along with attachment. How can I achieve this ? I am using r.setRequestBodyFromAttachment(attachment sys_id) method to send the attachment.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi all,
I have created this guide to give you a firm grasp on how to integrate with ServiceNow both inbound and outbound. In addition, also included on how security works using rest-api.