Webhook Query Parameters Not Being Sent With API Call

Good day, friends.

Now that I can see what is sent out and returned from https://openweathermap.org/api/one-call-api via webhook, thanks @ScruffR for pointing me to the “Events” section of the Particle web console (I can even expand each query to see what was sent and received in terms of data!), I notice that when I publish an event via the web console to trigger a call to the api, the query doesn’t seem to send my parameters despite configuring it to in the “Advanced” settings of the webhook builder. All it sends is the parameter name.

I’m specifically looking for daily rainfall forecast data, a single field in a large JSON object. The api call itself narrows the query to either hour, minute, daily, or current, (daily in my case) but no further. This is where I’ve attempted to add the webhook “Query Parameter” functionality to further refine, however, when I look at console -> events - > logs -> recent and look at the request sent via webhook to the api, it ends with “Rain= HTTP/1.1”, whereas my Query Parameter is {“Rain”: “{{{daily.rain}}}” } - per variable substitution documentation. Shouldn’t it append “Rain=daily.rain”?

Edit: Maybe I should look at using the custom response mustache templates instead?

Showing the definition of your webhook and the event payload that should trigger the webhook would be helpful :wink:

BTW, when you talk about “send my parameters” you may also need to clarify what stage of the sending you are refering to.
Your device sends an event to the cloud/webhook, this in turn sends a request to the openweather server, which then sends back the data you requested to the Particle cloud which will then be send the response - according to your response template - back to your device.

So which of the four sending actions are you refering to?

Right, sorry for the confusion.

I’m still testing by publishing events via the console.

Here’s what the webhook looks like.

Here’s what goes out:

GET /data/2.5/onecall?lat=removed&lon=removed&exclude=current%2Cminutely%2Chourly&appid=api key removed&Rain= HTTP/1.1
User-Agent: ParticleBot/1.1 (https://docs.particle.io/webhooks)
host: api.openweathermap.org
Connection: keep-alive

Here’s what comes back:

HTTP/1.1 200 OK
Server: openresty
Date: Wed, 13 May 2020 15:27:06 GMT
Content-Type: application/json; charset=utf-8
Content-Length: 3285
Connection: keep-alive
X-Cache-Key: /data/2.5/onecall?Rain=&exclude=current%2Cminutely%2Chourly&lat=removed&lon=removed
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true
Access-Control-Allow-Methods: GET, POST

{“timezone”:“America/New_York”,“daily”:[{“dt”:1589389200,“sunrise”:1589365779," etc etc

After putting this together, I’m starting to think that I should look into the custom webhook response templates to do the filtering instead of filtering in the query.

I’m not sure what you intend to do with your query but this is how mine looks

{
  "appid": "<redacted>",
  "cnt": 7,
  "units": "metric",
  "mode": "json",
  "q": "{{{PARTICLE_EVENT_VALUE}}}"
}       

the {{{PARTICLE_EVENT_VALUE}}} just holds the city I want to request the data for, but then I have the response template which actually filters the data I want forwarded to my device from the full set of data the request renders.
This is how my response template looks

{{city.name}},{{city.country}}/<{{#list}}{{temp.day}}~{{#weather}}{{id}}{{/weather}}/{{/list}}>         
1 Like

I like this approach better. I mean, using C to parse variable length arrays full of unpredictable fields is fun and all, but this seems cleaner and simpler. Now just have to test out the template syntax until I start seeing the right values.

The docs have this as the only example of a response template, how’d you come up with your format?

"responseTemplate": {
  "lat": "{{{results.0.location.lat}}}",
  "lng": "{{{results.0.location.lng}}}"
}

Thanks for the assist.

In terms of what I’m doing, I’m using an argon controlled relay featherwing to interrupt an existing irrigation system watering cycle when the forecast calls for rain of an amount equal to or greater than the average daily water a vegetable garden needs. Could I buy a newer internet enabled controller for the system? Probably, but then I wouldn’t learn to parse JSON or to work with APIs and webhooks.

You can try this response template

{ "daily": [{{#daily}} { "dt":{{dt}}, "rain":{{rain}} } {{/daily}}] }

with this query setting

{
  "lat": "<your latitude>",
  "lon": "<your longitude>",
  "exclude": "current,minutely,hourly",
  "appid": "<your token>"
}
1 Like

Interestingly, once I add a response template I no longer see the event go out and come back in the “Events” section of the console, even though it does pop up a notice that says “Event Published”. It does show up in the logs of the webhook itself, however, so I know it’s still working.

Now to set up the device to print the values received to see how the response template is behaving. Thanks for the head-start on the format.

Here’s the output based exactly on your solution:

{ “daily”: [ { “dt”:1589475600, “rain”: } { “dt”:1589562000, “rain”: } { “dt”:1589648400, “rain”: } { “dt”:1589734800, “rain”: } { “dt”:1589821200, “rain”:8.32 } { “dt”:1589907600, “rain”:0.39 } { “dt”:1589994000, “rain”:1.28 } { “dt”:1590080400, “rain”:0.73 } ] }

Thanks @ScruffR. InternetPoints++

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.