Webhook HTTP GET with duplicate query parameter

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.

https://ny3.blynk.cloud/external/api/batch/update?token=AbcdefgHIJklmnopqrstuvWxyZabcdeF&V0={{f}}&V1={{i}&V2={{c}}&V7={{lat)}&V7={{lon}}

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.

I edited the webhook URL as follows:

https://ny3.blynk.cloud/external/api/batch/update?token=AbcdefgHIJklmnopqrstuvWxyZabcdeF&V0={{f}}&V1={{i}}&V7={{lat}}&V7={{lon}}

My Argon sends this:
{
“name”: “blynk_lat_lon”,
“data”: “{"V0":-45.056999,"V1":30145,"lat":40.725418,"lon":-73.987991}”,
“published_at”: “2022-12-02T20:09:57.842Z”,
“coreid”: “confidential”
}

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.

It looks like you’re sending V0 and V1 in the event data instead of f and I so the template should have V0={{V0}}&V1={{V1}}

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

The URL is:

https://ny3.blynk.cloud/external/api/batch/update?token=AbcdefgHIJklmnopqrstuvWxyZabcdeF&V7={{{lon}}}&V7={{{lat}}}

I also tried:

https://ny3.blynk.cloud/external/api/batch/update?token=AbcdefgHIJklmnopqrstuvWxyZabcdeF&V7={{lon}}&V7={{lat}}

My best guess is the duplicate V7 argument in the URL is the problem.

I found a solution. Blynk has an alternative format of ?pin=longitude,latitude.

So a full URL for sending updating a location datastream ‘V7’ would look like this:

https://ny3.blynk.cloud/external/api/batch/update?token=AbcdefgHIJklmnopqrstuvWxyZabcdeF&V7=-74.123,40.321

The HTTP request sent to the webhook URL still looks garbled, but it is accepted by Blynk:

GET /external/api/batch/update?token=AbcdefgHIJklmnopqrstuvWxyZabcdeF&V7=-73.987991%2C40.725418 HTTP/1.1
User-Agent: ParticleBot/1.1 (https://docs.particle.io/webhooks)
host: ny3.blynk.cloud
Connection: keep-alive

Thank you for your help and patience.

If anyone else needs to do this, I am posting all of the details to my website:
https://savvymicrocontrollersolutions.info/particle.php?topic=particle-blynk

2 Likes

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