Dynamically change the query string of a webhook (GET request)

Hello everyone,

I am currently using the HttpClient library to upload to a server some variables. I would like to stop using this library and try out the Particle webhooks instead, but I am new to webhooks and I am not familiar with their usage yet.

I have a Photon reading temperature, humidity, and WiFi strength. All three variables are currently being sent to the server via a GET request (i.e. www. myserver .com/update?t=77&h=40&w=-67), but I have the capability of not uploading any value which does not meet certain criteria (like if temperature is very low it does not get updated in the server, i.e. www. myserver .com/update?h=39?w=-48)

Based on the above description I would like to know the following:
- Can I change the query string of the webhook at runtime, based on the values read by the Photon?
- Is there a way to catch the response status code (β€œ200”) from the webhook? I read that you could use hook-response to get the response body, but I wanted to know if there is a way of actually validating the response status code (200, 400, etc) inside my code.

Thank you all for your help!

Regards,
Manuel

Yes, but only if your server can handle a parameter that is there, but is empty, as in:

www.myserver.com/update?t=&h=39&w=-48

To do this, you would use the query section in the webhook configuration to set each of the parameters (t, h, w, etc.).

Then, in your Particle code, you would create a JSON object but only include the valid values.

The result values from the server are returned in a hook-response event, so yes, you can check the response from the device.

My tutorial:

1 Like

Great tutorial! I have no control over the server code, but will definitively try this. Thanks for your help :smile: