Example API query in Groovy

  • 1
  • Problem
  • Updated 2 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 2 years ago

  • 1
Photo of ilkeraktuna

ilkeraktuna

  • 4 Posts
  • 0 Reply Likes
Hi,

I'd appreciate any help...
Photo of Ravi Yadav

Ravi Yadav

  • 82 Posts
  • 8 Reply Likes
I've answered this in another thread you posted. Let me know if that helps.