My webhook performs a HTTP GET and in order to push out latitude and longitude values to the destination, the query parameter key needs to be included twice, as shown below for “V7”:
{
“event”: “blynk_set_datastream_vals”,
“url”: “https://ny3.blynk.cloud/external/api/batch/update”,
“requestType”: “GET”,
“noDefaults”: true,
“rejectUnauthorized”: true,
“query”: {
“token”: “AbcdefgHIJklmnopqrstuvWxyZabcdeF”,
“V0”: “{{f}}”,
“V1”: “{{i}}”,
“V2”: “{{c}}”,
“V7”: “{{lat}}”,
“V7”: “{{lon}}”
}
}
When I save the webhook, the second ‘“V7”: “{{lon}}”’ gets removed. This happens if I use the ‘custom template’ option, or the ‘webhook builder’ and entering each query parameter one row at a time. Any suggestions on how to get around this?
It’s not possible to include a duplicate query parameter because the query parameters are stored in a Javascript object, which does not allow duplicate keys.
What you can do is manually form the query string in the URL parameter, instead of using query. As long as your strings don’t need URL encoding, this should work.
It would look something like this, but I did not test it.
The URL format is clear to me. What I don’t understand is how to create a Particle webhook that will accept that complete URL from a particle.publish(). Everything seems to be JSON based. Also, the documentation states: When the “Request Type” is GET , the data can only be sent in the “Query Parameters”.
You can put that in the URL parameter. Make sure you don’t have the include default values setting, and don’t include any query parameters.
The reason it works is that the URL field also accepts the same mustache templates as the other fields, and you’re just building the query parameters for the GET by hand, instead of having the webhook server do it for you from the query object.
The HTTP request sent to the webhook url
GET /external/api/batch/update?token=AbcdefgHIJklmnopqrstuvWxyZabcdeF&V0=&V1=&V7%5B0%5D=40.725418&V7%5B1%5D=-73.987991 HTTP/1.1
User-Agent: ParticleBot/1.1 (https://docs.particle.io/webhooks)
host: ny3.blynk.cloud
Connection: keep-alive
I edited the token value above only. Notice “&V0=&”. The substitution isn’t working.
Good catch! That was an embarrassing mistake on my part. I am able to process a floating point value and a integer without an issue using the URL. But when I try to (only) process the latitude and longitude pair of values, I get a corrupted HTTP request:
The source event that triggered the webhook:
{
“name”: “blynk_lat_lon”,
“data”: “{"lat":40.725418,"lon":-73.987991}”,
“published_at”: “2022-12-02T22:23:30.936Z”,
“coreid”: “confidential”
}
The HTTP request sent to the webhook url:
GET /external/api/batch/update?token=AbcdefgHIJklmnopqrstuvWxyZabcdeF&V7**%5B0%5D=-73.987991&V7%5B1%5D**=40.725418 HTTP/1.1
User-Agent: ParticleBot/1.1 (https://docs.particle.io/webhooks)
host: ny3.blynk.cloud
Connection: keep-alive