I was using the Sonos Weather forecast announcement smart app before WU API was retired:
today I decided to fix it adapting to the new Wetaher Company API.
But whatever I do , the app throws an exception with “unauthorized” reason.
On the app there’s this code which makes the httpget:
private loadText() {
def deviceListParams = [
uri: "http://api.wunderground.com",
path: "/api/30c246ea43c71204/forecast/lang:TR/q/TR/İstanbul.json",
headers: ["Content-Type": "text/json", dataType : "jsonp"]
]
def forecast = [:]
httpGet(deviceListParams) { resp ->
log.debug "response:"
log.debug resp
if(resp.status == 200)
{
forecast = resp.data
}
else
{
log.debug "http status: ${resp.status}"
}
}
log.debug "forecast: ${forecast}"
Here , the post was made requesting json format
Of course because of the changed APı now the key does not exist and I get “unauthorized”.
But even after changing to the new API format with following parameters:
uri: "https://api.weather.com",
path: "/v3/wx/forecast/daily/5day?icaoCode=KDEN&units=e&language=en-US&format=json&apiKey=XXXXXXXXXXXXXXXXXXXXXXXXXX",
I still get following exception:
roovyx.net.http.HttpResponseException: Unauthorized @line 428 (loadText)
I am sure that the new API KEY is working because when I use this URL on my browser I can get a valid response.
So what is wrong with the code ?
And I am not a WU fan, if there is a better way of getting weather forecast, I’d be glad to use it.
Waiting for any recommendations…
thanks.