REST from script include

maneesh3
Tera Contributor

Hi,

How to call REST api resource path (GET) from script include to trigger REST method.

Please help in this

 

 

Thanks a ton!

 

1 ACCEPTED SOLUTION

Nootan
ServiceNow Employee
ServiceNow Employee

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

View solution in original post

10 REPLIES 10

Nootan
ServiceNow Employee
ServiceNow Employee

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