Example API query in Groovy

  • 1
  • Problem
  • Updated 3 years ago
Hi,

I am trying to get query results for my SmartThings app.
Smartthings uses Groovy and I  have  an example for other weather provider API. (openweathermap)

However, I can't get response from weather underground API.
It complains about output format not being specified.

How can I correct my httpget request ?

<pre>
you must supply a valid output format, type:invalidformat], features:[:]
</pre>

example for openweather :

def makeJSONWeatherRequest() {

   def params = [

        uri:  'http://api.openweathermap.org/data/2.5/',

        path: 'weather',  

        contentType: 'application/json',

        query: [q:'İstanbul,tr', mode: 'json', appid: '2a2e4a0fafcc0bd5039deaaf47549fdac', lang: 'tr']

    ]

    try {

        httpGet(params) {resp ->

            log.debug "resp data: ${resp.data}"

            log.debug "humidity: ${resp.data.main.humidity}"

            def hum = ${resp.data.main.humidity}

        }

    } catch (e) {

        log.error "error: $e"

    }

}

Photo of ilkeraktuna

ilkeraktuna

  • 4 Posts
  • 0 Reply Likes

Posted 3 years ago

  • 1
Photo of ilkeraktuna

ilkeraktuna

  • 4 Posts
  • 0 Reply Likes
hi,

I'd appreciate any replies please...
Photo of JLo

JLo

  • 6 Posts
  • 1 Reply Like
Hi,

You don't show your code so it makes it hard to comment on why it doesn't work.  I looked in the SmartThings community but I didn't find anything that might be your app.

For an example talking to WU, you might look at the SmartApp weather-underground-pws-connect.groovy in the SmartThingsPublic repo.

John
(Edited)
Photo of Ravi Yadav

Ravi Yadav

  • 82 Posts
  • 9 Reply Likes
Add format: 'json' in your parameters list.