REST/HTTP call

rest
Tags: #<Tag:0x00007fadf7e35510>

(jay) #1

I have OH2 on my local box and able to setup simple actions.
I am trying to make a REST call to some external system. I checked Yahoo weather and i am able to make it work. But i am trying to understand how OH2 allows to make external REST calls.

Option1 : I was thinking that http binding should allow me to do it directly. But i do not see anything for my http binding even i have Bindings.

Option2: I was thinking that REST call should allow me to make external call directly in OH2 but i see only REST API Docs in bindings.

Not sure how to make simple REST call to external system and capture the results.

Any help is appreciated.


(Patrik Gfeller) #2

Have a look into the following post to see an example of a more complex request from a OH rule:

For a simple call with get parameters sendHttpGetRequest(httpRequest) should be enough:

    val yahooWeatherLocationId = "782306"
    val httpRequest = "https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20weather.forecast%20where%20woeid%3D" + yahooWeatherLocationId + "&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys"
    val String yahooWeatherJSON = sendHttpGetRequest(httpRequest)

with kind regards,
Patrik


(jay) #3

Thanks for the example. As mentioned i am new to OH2

Here are the steps i might need to do to connect to external REST service.

  1. Declare Items
  2. create Rule - Make a call to service and convert Json response to Objects. Update Items
  3. sitemap link.

is my understanding correct…?


(Patrik Gfeller) #4

yep - that’s right; let me/us know if you need help with one of the steps.