send data from ServiceNow to other applications using REST

dini1
Tera Contributor

Hi, I have to send couple of fields info to an application via REST. I went through wiki but couldnt understand much. Can someone please let me know how to do it.

I understand that I have to go to REST Message and update the end point. Lets say I have 3 fields A, B, C, which I need to send the info of these fields to an external application. Now when I get inside POST, what should I do now? Thanks.

7 REPLIES 7

srinivasthelu
Tera Guru

Hi Dinesh,



You are almost there.


1. Define the content that you wanted to post in the content box.


2. If you wanted to have   dynamically include values in the content, You can use either setStringParameter or setRequestBody of the Rest MessageV2 class.



More here RESTMessageV2 API - ServiceNow Wiki



Thanks


Srinivas


Mrudula6
Mega Guru

Hi Dinesh,



You can use r.setStringParameter("xyz","A") in the Business rule/server code which you are writing in ServiceNow to send the data to REST API. In your REST API below the header section just substitute the JSOn value with ${var_name}. You need not do it in post method.That will do the work. To access value you send from your server code write it in ${} pair. You can refer to screenshot below.



From my BR, I had sent r.setStringParameter("auth_code","A") and in REST API I accessed using below method.



find_real_file.png



You can also refer below links along with one given by Srinivas



Outbound REST Web Service - ServiceNow Wiki


dini1
Tera Contributor

Hi Mrudula, I have created a BR as below, passing 2 fields(u_endpoint and u_sites) in the table from where I wanted to send the data. The values that I pass are used in 'Content' in the HTTP Method - post, as in the pic. Am I right in doing that?


FYI ... The external application expects values as inendpt and insites and thats why I have used inendpt=${endpt}&insites=${sites}. Am I right here?



var r = new RESTMessage('VR', 'post');


r.setStringParameter('u_endpoint', endpt);


r.setStringParameter('u_sites', sites);


var response = r.execute();


}



find_real_file.png


tony_barratt
ServiceNow Employee
ServiceNow Employee

Hi BD,



In addition to what has already been said, make sure the documentation you are looking at is aligned withe the version of your instance.



For example this link here is for Fuji - because RESTMessageV2 did not exist for Eureka


RESTMessageV2 API - ServiceNow Wiki



The links here are for Geneva


Create a REST message


Generate a REST message script preview



Also I suggest taking a look at the OOB outbound REST messages to get an overview.




Screen Shot 2016-05-26 at 6.58.24 AM.JPG



How are you getting on?


Any blocking issues?



Best Regards



Tony