Hey!
I am using the HTTP GET command in Honeyscript to fetch a JSON through an API.
I want to use an advanced flow to extract only a portion of the JSON file and convert it to a text tag with the «Analyze» card. This is to send a push notification, much like in the «chuck norris» example given by Homey when you open your first advanced flow.
However - I get my fetch the JSON without any errors, but I have no idea how to output the JSON through a @result tag that I can use in the «Analyze» card.
The GET HTTP flow card is unable to complete the fetch, even with the same parameters I use in the homeyscript, that’s why I’m not using the built in GET function.
So, the question is really, what bit of code should I enter in the homeyscript to make a JSON output I can use further out in my advanced flow?
MUCH appreciated!
Personally I try to do as much as possible in HS, this is basically the script I use the below,
i’ve commented the file for your convenience
let key = "XXXX" ;
let loc = "51.246,5.123" ;
let url = "https://weerlive.nl/api/json-data-10min.php?key="+key+"&locatie="+loc ;
//requesting the data
let response = await fetch(url);
//if response is not OK
if(!response.ok) throw new Error('Failed to query');
//else process the response in the html variable
//since i'm expecting json i want it to be treated as json
let html = await response.json();
//to view the output uncomment the line below
//console.log(html)
//i'm only interested in the data shown after the "liveweer[0]"
html = html.liveweer[0] ;
//retun that data to be used on another card
return html ;
4 Likes
Thanks so much for the comments in the code! I will try this and see how it works out.