- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-30-2020 10:26 PM
Hi,
How to call REST api resource path (GET) from script include to trigger REST method.
Please help in this
Thanks a ton!
Solved! Go to Solution.
- Labels:
-
Integrations
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-31-2020 10:15 AM
Hi Maneesh,
For this, You can use this code.
var RESOURCE_PATH = 'api/..etc'
var request = new sn_ws.RESTMessageV2();
request.setEndpoint('https://INSTANCE.service-now.com/'+RESOURCE_PATH );
request.setHttpMethod('GET');
//Eg. UserName="admin", Password="admin" for this code sample.
var user = 'admin';
var password = 'admin';
request.setBasicAuth(user,password);
//If having any requestBody
request.setRequestBody(JSON.stringify(requestBody));
request.setRequestHeader("Accept","application/json");
var response = request.execute();
gs.log(response.getBody());
Thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-31-2020 01:50 AM
Hey,
Please go through the link may be this is helpful to you
Please mark correct or helpful if this solves your issue.
Thanks
Swapnil
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-31-2020 12:54 AM
Hi Maneesh,
You can try this code.
try {
var r = new sn_ws.RESTMessageV2(REST Message, REST Method);
//override authentication profile
//authentication type ='basic'/ 'oauth2'
//r.setAuthenticationProfile(authentication type, profile name);
//set a MID server name if one wants to run the message on MID
//r.setMIDServer('MY_MID_SERVER');
//if the message is configured to communicate through ECC queue, either
//by setting a MID server or calling executeAsync, one needs to set skip_sensor
//to true. Otherwise, one may get an intermittent error that the response body is null
//r.setEccParameter('skip_sensor', true);
//Append a parameter to the end of the request URL with the form name=value.
r.setQueryParameter(name, value)
//Set a REST message function variable with the specified name from the REST message record to the specified value.
r.setStringParameter(name,value)
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
}
catch(ex) {
var message = ex.message;
}
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-31-2020 02:34 AM
Hi Nootan,
Thanks a lot for reply.
How can I call REST resource path (GET) method instead of message name.
new sn_ws.RESTMessageV2(REST Message, REST Method);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-31-2020 03:42 AM
Hi Maneesh,
Can you share the REST resource path to which you are referring to ?
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-31-2020 04:53 AM