« Back to full topics list
0
0
ANSWERED
Marked as spam
Posted by - Asked on January 28, 2019 9:29 am - 416 views

1 Replies

0
Private reply

Hi Ira,

You can certainly call any API from scriptr.io and read the response. I wrote a sample for you below using a third party weather service (openweathermap.org). If you want to use the same service, make sure to replace the API Key (appid parameter) with your own API Key which you can get when you create an account.

var lat = 35;
var lon = 139;
var weatherApi = "http://api.openweathermap.org/data/2.5/weather?appid=XXXXXXXXXXXXXXXXXXX&lat=" + lat + "&lon=" + lon;

var http = require("http");
var response = http.request({
		url : weatherApi
	});

if (response.status == "200") {
	var weatherInfo = JSON.parse(response.body);
	return weatherInfo;
} else {
	return "Ooops, there was a problem retrieving weather information!";
}

I hope this helps.

Julien

Marked as spam
Posted by - Replied on January 28, 2019 10:19 am

It certainly does, thank you.

I tried the sample in the Scriptr documentation under the section ”what can a script do?” , but it generated errors. Your suggestion of openweathermap.org is exactly what I needed.

Thanks again, Ira

( at January 28, 2019 9:26 pm)

You’re right, the third party used to get weather info modified their API and now it requires to be called over HTTPS only.

Thanks for informing us!

Julien

( at January 30, 2019 9:06 am)