Outbound Rest Message using get method
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-01-2017 11:36 PM
Hello,
I have used below background script to test the functionality and getting the below error.
What need to be checked from the endpoint url?
(function sample_http_request() {
try {
var request = new sn_ws.RESTMessageV2();
request.setHttpMethod('get');
request.setEndpoint('http://localhost:8080/xxx?id=1234');
var response = request.execute();
var httpResponseStatus = response.getStatusCode();
var httpResponseContentType = response.getHeader('Content-Type');
var parser = new global.JSONParser();
var parsed = {};
var httpResponseBody;
gs.debug("http response status_code: " + httpResponseStatus);
gs.debug("http response content-type: " + httpResponseContentType);
// if request is successful then parse the response body
if (httpResponseStatus == 200 && httpResponseContentType == 'application/json') {
httpResponseBody = response.getBody();
// parse JSON string returned from request into a json object
parsed = parser.parse(httpResponseBody);
// iterate over JSON object only printing the id property of JSON objects in results array
for (var i = 0; i < parsed.results.length; i++) {
gs.print('id: ' + parsed.results[i].id)
}
}
}
catch (ex) {
var message = ex.getMessage();
gs.debug(message);
}
})();
- Labels:
-
Integrations
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-02-2017 12:29 AM
Hi,
Please find this code. You can try running this.
var request = new sn_ws.RESTMessageV2();
request.setEndpoint('https://test.service-now.com/api/now/table/incident?sysparm_fields=number&sysparm_limit=1');
request.setHttpMethod('GET');
var user = 'admin';
var password = 'admin';
request.setBasicAuth(user,password);
request.setRequestHeader("Accept","application/json");
var response = request.execute();
gs.log(response.getBody());
var httpResponseStatus = response.getStatusCode();
gs.log(httpResponseStatus);
You can modify the code accordingly and see if it works.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-02-2017 01:11 AM
Hi saranya babu,
Instead of this end point request.setEndpoint('http://localhost:8080/xxx?id=1234'); please put this request.setEndpoint(give your instance endpoint);
Please click helpful,correct answer,like
Thanks,
Raminaidu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-02-2017 01:36 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-02-2017 01:44 AM
Hello Avinash.
I have used the below code and am getting the result.
What might be the my issue?In the that thirdparty url access need be checked?
var request = new sn_ws.RESTMessageV2();
request.setEndpoint('https://sample.service-now.com/api/now/table/incident?sysparm_fields=number&sysparm_limit=10');
request.setHttpMethod('GET');
var user = 'userid';
var password = 'paswrd';
request.setBasicAuth(user,password);
request.setRequestHeader("Accept","application/json");
var response = request.execute();
gs.log(response.getBody());
var httpResponseStatus = response.getStatusCode();
gs.log(httpResponseStatus);
[0:00:06.570] Script completed in scope global: script
*** Script: {"result":[{"number":"INC0010001"},{"number":"INC0010002"},{"number":"INC0010003"},{"number":"INC0010004"},{"number":"INC0010005"},{"number":"INC0010006"},{"number":"INC0010007"},{"number":"INC0010008"},{"number":"INC0010009"},{"number":"INC0010010"}]}
*** Script: 200