How to pass x-www-form-urlencoded type of body in HTTP method in Outbound Rest message

Adii17
Tera Contributor

Hi, how can we convert this x-www-form-urlencoded body into JSON in the HTTP method?

Adii17_0-1718029068478.png

Adii17_1-1718029134875.png

 

Regards,
Aditya

 

7 REPLIES 7

Community Alums
Not applicable

Hi @Adii17 ,

 

To convert first remove the Content-Type: application/x-www-form-urlencoded and update it to the below-

Content-Type: application/json

 

In the content section you need to update in the below format-

{
    "grant_type": "client_credentials",
    "scope": "service_access",
    "client_id": "0oa20ugcb60Kxxxxxxxxxxxx",
    "client_secret": "CEq15fZf4Xn-3WWFxxxxxxxxxxxxxxxx"
}

  

If my response has resolved your query, please consider giving it a thumbs up ‌‌ and marking it as the correct answer‌‌!

 

Thanks & Regards,

Sanjay Kumar

@Community Alums  Hi Sanjay, Could you please comfirm, how to accomodate attached form-data in outbound REST API ? I am using setRequestBodyFromAttachment() method to send attachment. Appreciate your response.Screenshot 2025-03-05 220953.png

Community Alums
Not applicable

Hi @SandyNow ,

You can easily do this via the below line of code - 

 request.setRequestBodyFromAttachment('<attachment sys_id>');

 

Take a look at this official documentation from ServiceNow-
https://developer.servicenow.com/dev.do#!/reference/api/xanadu/server/sn_ws-namespace/c_RESTMessageV...

 

Also you can try to look into this- https://developer.servicenow.com/dev.do#!/reference/api/yokohama/rest/c_AttachmentAPI#attachment-POS...

 

 

@Community Alums Thanks for taking time to respond. Actually i am sending attachment to 3rd party application through Outbound REST API. 3rd Party app#endpoint is expecting 'input_file' with attachment but I am not sure where to put 'input_file' in REST Message. Below is my BR.

Appreciate your response.

 

 

var resultGr = new GlideRecord("sn_customerservice_case");
resultGr.addQuery("sys_id", current.table_sys_id);
resultGr.addQuery("account", '<account sys id>'); // running for specific account
resultGr.query();
if (resultGr.next()) {
var caseid = resultGr.sys_id.toString();
gs.info("Case sys id : " + caseid);
try {
var r = new sn_ws.RESTMessageV2('New Integration', 'UploadAttachment');
r.setRequestBodyFromAttachment(current.sys_id);
r.setRequestHeader("Content-Type", resultGr.content_type);
r.setStringParameterNoEscape('request_id', resultGr.correlation_id);

 

var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
gs.info("The value of the POST Response is " + httpStatus + "Body : " + responseBody);
} catch (ex) {
var message = ex.message;
}
}