Storing JSON data back from a POST request

Have solved my problem with the awesome help from @robertklep over on the Slack channel

For the HTTP request cards, you can specify advanced options in the URL box - and the gold was that you can include the payload/body as a json in that url string. So what I’ve done is:

1 flow that does the web service call - using a GET JSON trigger object. Using advanced options you enter the full string into the url field - so in my case I needed to do a POST and therefore the url field was: {“method”:“post”,“protocol”:“https:”,“host”:“SITE.HERE”,“path”:"/a/nz-akl/realtime",“json”:{“stop_id”:1234,“trips”:{“45678”: {“departure_time_seconds”:20,“route_short_name”:“267”}}}, “headers”:{“Accept”:“application/json”, “Content-type”:“application/json”}}

I then set up a second flow with a JSON object trigger, and in the action I used a JSONpath Better Logic card to extract the JSON to a variable which I then calculate the number of stops to my bus stop. Also if in the first flow the web service returned no results (ie bus not operating on that route yet, then I set the number of stops to 0)

Then in a third flow I had a Better Logic variable trigger on change, and this plays a message to a smart speaker using a Home Assistant command announcing the number of stops

I hope this helps someone else along the way

2 Likes