Homey Community Forum

Calling an external service and receiving the Response in a variable?

tools
app
#1

a HTTP (POST) call in any browser to a external service returns the data (unixdate, Kelvin-temperatures and the moisture for a specific area i am interested in.

I want to make the call once or twice a day and put the response in the appropiate variables (better logic i.e.).

I expect that one of the HTTP calls in the HTTP app could do the job, but with so many cards and options i need some help/hint in a HowTo solution, anyone can Help ???

Example:
Actual Call (i.e.):
http://api.agromonitoring.com/agro/1.0/soil?polyid=5cc5c0f3d86170003e090a62&appid=afb5821958544dc9fedba14e4e46f849

Actual Response (i.e.):
{“dt”:1556452800,“t10”:284.6,“moisture”:0.146,“t0”:290.74}

1 Like
#2

Maybe with the HTTP app from @Erik ?

#3

Thx, but what to put where in the suggested Get card?
Shout it be:

  • url without parameters inurl (i.e. http://api.agromonitoring.com/agro/1.0/soil )
  • ?polyid=5cc…?appid=afb5… in JSONpath ( but then in JSON format… {“polyid”:"5cc… , “appid”:“afb5…”}
  • variable: a Better Logig Variable (type string?) to hold the response?
    And in a separate flow breakdown of Response in different variables ?

This are some of the choices i consider te make, thats why i try to find some specialists for help…

#4

Replied via PM with working example :slight_smile:

#5

Would u mind to put the working example also here for future reference?
@Erik ^^

3 Likes
#6

Thx, i understand your solution but on my Homey i now have a problem to use any TAG,
whenever i select one, Homey app aborts. Have to solve this first before i can implement your example.

#7

Have you tried it with a browser via flow.homey.app?

#8

Thx that is the solution, Safari IPhone 5 was the problem…
Everything works now.

#9

A Nice and relative simple solution for a quite common problem when calling external services that can be called with HTTP. Please ASK Erik to put iT as reply on this forum.
By the was, one has to use the browser as Erik suggested.

#10

@Erik, @Arnfinn_Gilberg,

Hi Erik,

As suggested by Jef and previously asked by Roco. Can you please share the solution you sent to Jef? Both Arnfinn and myself are also looking for this solution.

#11

And scrolling by this topic again I noticed it was Jefs first post and i failed to welcome him to the Homey community and hope he’ll share and experience the fun and ease of Homey! Welcome Jef!

#12

Talked to Erik and when he finds some time he will post the solution here. :wink:

#13

Hi all,

Sorry for this delayed response, but I had to find some time for it.
There are several ways to build the flows @Jef_van_Leeuwen requested.
Because he wants to map multiple values from the same HTTP response it’s best to make 2 flows with combine cards GET JSON trigger object (A24), JSON object (T81) and JSONpath Better Logic (A80).
(Native Homey logic support is in development, but for now we rely on BetterLogic for storing variables).

When in doubt validate your JSON values for flow cards with jsonlint.com. Check your JSONpath expressions with jsonpath.com. If you’re using JSONpath expressions on XML responses, be aware of the XML to JSON conversion. This conversion can be simulated on RunKit.com with the xml2js module.

The first flow will do a get request. The returned response will be available in the JSON token on the trigger of the second flow.
In the second flow this JSON token can be used in the action cards, where the desired value is queried by JSONpath and put in Better Logic variables.

Preparation - Define Better Logic variables:

Flow 1 - Request (poll every hour):

Flow 2 - Extract values and map to Better Logic:
Flow 1 triggers this flow because of the matching trigger-name ‘MonitorUpdate’

1 Like
#14

Hi @Erik,

Very much appreciated to share the example for all to learn and benefit!
I will look into it and see if I can convert it to read an XML string from a local web server and send that to a variable! If anyone else has valid examples of how to work with the magnificent but in my opinion not simple :wink: HTTP request flow cards app please post these on this forum!