The CreatorCon Call for Content is officially open! Get started here.

Shubhangi Suman
Kilo Explorer

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();

Comments
Community Alums
Not applicable

Thanks

paphavich
Tera Explorer

Thanks, It's Worked!

vyshnavi8
Tera Expert

THANKS IT HELPED ME

SandyNow
Tera Contributor

@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.

Screenshot 2025-03-05 220953.png

SandyNow
Tera Contributor

@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.

Screenshot 2025-03-05 220953.png

BillMartin
Mega Sage
Mega Sage

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.

 

Version history
Last update:
‎05-03-2021 04:09 AM
Updated by: