I'm having trouble reading custom webhook return values All questions

Hello, 

I'm calling the following url successfully: https://api.forecast.solar/estimate/watthours/day/42.6977/23.3219/22/-45/2.8 

The returned JSON is the following:

{

  "result": {

    "2023-04-07": 8108,

    "2023-04-08": 3016

  },

  "message": {

    "code": 0,

    "type": "success",

    "text": "",

    "info": {

      "latitude": 42.6977,

      "longitude": 23.3219,

      "distance": 0,

      "place": "Souvenirs Bulgaria, бул. Тодор Александров, Център, Средец, София, Столична, София-град, 1000, България",

      "timezone": "Europe/Sofia",

      "time": "2023-04-07T23:49:02+03:00",

      "time_utc": "2023-04-07T20:49:02+00:00"

    },

    "ratelimit": {

      "period": 3600,

      "limit": 12,

      "remaining": 6

    }

  }

}

I would like to obtain the value of the first returned value "8108" in a variable.

I managed doing that using the option "Use JSON structure" enabled and assigning "result-2023-04-07" to a variable.

However this method is not working for me because the dates are changing and I tried capturing the returned value with "Use JSON structure" disabled and using a coma separated list "pa,pb,pc". When I assign to variables {pa} , {pb} and {pc}, I get the following three values "Array", "Array" and Empty.

I assume I'm doing something wrong here and thus looking for a help.

Asked by Svetozar Rusinov on April 8, 2023, at 5:12am

Hi Svetozar, I think the problem is that when you provide names for the parameters it is only looking at the top level values.  So in your example the following happens:

  • pa is given the array 'result'
  • pb is given the array 'message'
  • pc becomes empty because there are no more entries at that level

This is probably an oversight in the way it has been built - the way you're expecting it to works makes more sense to me.

Can you create a new test sequence with the same webhook call in it? I can then use that to do some testing and implement a fix.

This is awesome!

I have created a new sequence: "webhook weather forecast

It is disabled at the moment, but you can enable it.

Btw, kudos for the web service you are building, I like the concept a lot, the ability to integrate different home automation platforms altogether with a 3rd part service is something very useful and I see a lot of potential.

Maybe you can think about some more flexible way to describe nested JSON structure and pickup specific values from it, like using JSON schema as formatting or something simpler: 


Post a reply

The SEQUEmatic bot is still new and learning. If you don't get the answer you need, just ask to speak with Derek and your chat will be transferred.