I’m trying to use a webhook to retrieve weather data from forecast.io. I have create the webhook and am able to publish it and get a response, but the response is always the full json text, rather than the filtered version I want using the responseTemplate I provided.
Creating a webhook with the json from that page and testing it with particle-cli also yields the entire json rather than the mustache-filtered version.
I’ve tested my responseTemplate string using trymustache.com and it seems correct.
@Dave or @peekay123, is there an issue with the webhook responseTemplate field or is it just something I’m doing wrong?
And the response text is very long and identical to what you see if you browse to https://api.forecast.io/forecast/<api key>/45.464698,-98.486483
The webhook isn’t even adding the parameters I specify in “query” to the url when it makes the request (so I get the full text of minutely, hourly, daily and flags in my json).
@Dave, wondering if you’ve had a chance to check this out. I’m working on this as part of what I hope will be a Christmas present. Haha. At this point I’m thinking of doing the parsing using some intermediary and then using the webhook to retrieve that but I’d really like to just use the webhook directly. Thanks!
Thanks for the tutorial link. That would definitely work and I may have to go that route if I can’t get the webhook working the way it should. If really rather not have an extra piece of code hanging out at hook.io though since the webhook should really be able to do what I need. We’ll see. Hopefully I’ll get the webhook straightened out.
Thanks again for providing input. I’ve been following your thread for ideas also.
FYI I’m using forecast.io through hook.io for my what should I wear clock. I just prefer understanding what happens when fetching and parsing the data instead of relying on the slightly mysterious webhook configuration. The code is open source if you want to look.
@Dave, thanks for the suggestion. My understanding of Mustache is that you use #currently to “open” the currently element at the root of the JSON and then you can reference all of the elements under it directly. Then you use /currently to “close” the currently section.
I previously tested this template on trymustache.com and this webhook is actually directly taken from a project another user made and I have confirmed that it is indeed working correctly for him.
Also, in addition to the responseTemplate not working, the webhook seems to also be ignoring what I have specified in the query parameters as well (“exclude=…” never gets appended to the request URL).
Also, just to clarify… if elements in the responseTemplate don’t match the structure of the JSON, what would the expected behavior be? Would you anticipate that the entire JSON would be returned? Or wouldn’t it just fail to find the elements specified in the template and not return anything?
@bennettj1087 the response template is a mustache template. If a key doesn’t match, that section will be blank. You could use an inverted section {{^person}} to insert content if person is missing. See here for the full spec.
Of course that doesn’t help you right now since webhook creation seems broken.
Wow, thanks for identifying that bug! We quickly fixed and confirmed the fix (Thanks @kennethlimcp) (issue here https://github.com/spark/particle-cli/issues/186 ). I haven’t published a new version of the CLI yet, but if you install it from source you’ll have the fix. I want to make sure there aren’t any other sneaky bugs in there before I publish a release.
Also, I’m sorry this regression made it into the CLI, we’ll try to keep a closer eye on changes coming through.