send data from ServiceNow to other applications using REST
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-25-2016 08:48 PM
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.
- Labels:
-
Integrations
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-25-2016 09:00 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-25-2016 09:17 PM
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.
You can also refer below links along with one given by Srinivas
Outbound REST Web Service - ServiceNow Wiki
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-26-2016 02:21 AM
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();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-25-2016 10:00 PM
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
Generate a REST message script preview
Also I suggest taking a look at the OOB outbound REST messages to get an overview.
How are you getting on?
Any blocking issues?
Best Regards
Tony