- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2022 07:40 PM
I made JSON on OpenWeatherMap like below and I tried to call REST Massage in Script-Background of ServiceNow by entering JSON's script below and clicking "Run Script".However I couldn't call REST Massage.
If someone knows solution, please let me know.Thanks.
[JSON]
try {
var r = new sn_ws.RESTMessageV2('application name, 'title');
r.setStringParameterNoEscape('timezoon', '322440');
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
}
catch(ex) {
var message = ex.message;
}
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2022 07:55 PM
you need to set the end point.
(function execute() {
var restMessage = new sn_ws.RESTMessageV2();
restMessage.setEndpoint('https://api.openweathermap.org/data/2.5/weather?zip='+ YOUR_ZIP_CODE +'&appid='+ YOUR_KEY);
restMessage.setHttpMethod('get');
var response = restMessage.execute();
var httpResponseStatus = response.getStatusCode();
if (httpResponseStatus == 200) {
var responseBody = response.getBody();
var responseObject = JSON.parse(responseBody);
// do what you need to do with the response
return body;
}
})()

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2022 07:55 PM
you need to set the end point.
(function execute() {
var restMessage = new sn_ws.RESTMessageV2();
restMessage.setEndpoint('https://api.openweathermap.org/data/2.5/weather?zip='+ YOUR_ZIP_CODE +'&appid='+ YOUR_KEY);
restMessage.setHttpMethod('get');
var response = restMessage.execute();
var httpResponseStatus = response.getStatusCode();
if (httpResponseStatus == 200) {
var responseBody = response.getBody();
var responseObject = JSON.parse(responseBody);
// do what you need to do with the response
return body;
}
})()
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-15-2022 07:42 PM
Thank you for your help!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2022 02:50 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2022 10:30 PM
Hi Haruna,
Is the url working from REST Message? Click on the "Test" link to test the url.
Following code probably won't work. Should this be "timezone"? If so, should the value be "Asia/Tokyo"? Or is the parameter suppose to be "timezone_offset"?
r.setStringParameterNoEscape('timezoon', '322440');