- 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-30-2020 10:34 PM
Hi Maneesh,
You can use the REST API Explorer to build your REST request. The related links near the send button will give you code snippets for integrating to the ServiceNow APIs in several commonly used languages. More info here.
-Pradeep Sharma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-31-2020 12:47 AM
Hi Pradeep,
Actually Iam working on web phone integration so I need to call scripted REST api (resource path) from script include to trigger REST and add info message
please help me with the code .

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-30-2020 10:56 PM
Hi maneesh,
You don't need to include it. When you create your Script Include, it is loaded into the accessible script cache. From inside your Scripted Rest API, you can directly call the Script Include (as long as it is Active) in this way:
Script Include Name: MyScriptInclude
If your API is in the same scope as your Script Include:
var myinclude = new MyScriptInclude();
If it is in a different scope:
var myinclude = new script_include_scope_prefix.MyScriptInclude();
Or You can use it-
Script include GET example
This example demonstrates how to use a script include to provide a response. By using a script include you can reuse common code and maintain readability in the REST service scripts.
/** * GET - Sample Request API - Script Include */ (function process(/*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) { var responseObj = global.SampleDataUtil.getSampleJSON(); return responseObj; })(request, response);
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:05 AM
Hi soni,
Thanks for your fast response.Actually Iam working on web phone integration so I need to call scripted REST api (resource path) from script include to trigger REST and add info message
please help me with the code .