how to send outbound Request n JSON format in REST

sumitjumale
Kilo Contributor

Hi All,

I have created REST Outbound Message. I am able to recieve response in JSON format, but I want to send the outbound request in JSONformat.

Please suggest.

Response:

find_real_file.png

Request:

find_real_file.png

Regards,

Sumit Jumale

5 REPLIES 5

Swapnil Bhakar1
Mega Guru

Hi Sumit,



While sending a request in json format you can use REST API explorer and fill the required info. in fields.


Please see below screenshot how to send response in JSON format.


In request headers pass the request format value as application/json. So it will send a request in JSON format.



find_real_file.png



In below screenshot you can able to see request sent in JSON format.



find_real_file.png



Hope it will helps you.



Regards,


Swapnil



PS: Hit like, Helpful or Correct depending on the impact of the response


Thanks for quick reply Swapnil.



I am send request outbound through code written in Business rule. In this case i can not use Rest API Explorer to send the request in JSON format.


Please suggest some way to send request through code in JSON format.



Regards,


Sumit


Hi Sumit,



You can refer below script in your Business rule.



var request = new sn_ws.RESTMessageV2();


request.setEndpoint('https://your instance name.service-now.com/api/now/table/incident');


request.setHttpMethod('POST');



//Eg. UserName="admin", Password="admin" for this code sample.


var user = 'admin';


var password = 'admin';



request.setBasicAuth(user,password);


request.setRequestHeader("Accept","application/json");


request.setRequestHeader('Content-Type','application/json');


var response = request.execute();


gs.log(response.getBody());



Use the above bold highlighted lines in your business rule.



Hope it will helps you.



Regards,


Swapnil



PS: Hit like, Helpful or Correct depending on the impact of the response


Deepa Srivastav
Kilo Sage

Can I ask what you are trying to test, Scripted REST APIs or ? You can send request by REST message also.




Mark Correct if it solved your issue or hit Like and Helpful if you find my response worthy.