I’m trying to use an Argon as a gateway to a number of Xenons sending sensor data over BLE and I want to use a webhook to forward that on to a IoT server (ThingsBoard). When you post telemetry, you select what device you want from the API by encoding an API key in the URL. For now, I have hard coded the API key for each Xenon device in it’s firmware, and now the Argon can do a Particle.publish of the following data:
{"sensorName": "BLE-Xen1"; "apiKey"="xxxxxxxxxxxxx"; "randomNumber": 39810; "temperature": 23.80; "humidity": 64.70}
I have set up the webhook as follows using the example in the docs, for variable substitution:
{
"event": "BLEgwData",
"deviceID": "xxxxxxxxx",
"url": "http://myserver.net:8082/api/v1/{{{apiKey}}}/telemetry",
"requestType": "POST",
"noDefaults": true,
"rejectUnauthorized": false,
"json": "{{{PARTICLE_EVENT_VALUE}}}"
}
However the webhook call fails.
Event:
{
"name": "BLEgwData",
"data": "{\"sensorName\": \"BLE-Xen1\"; \"apiKey\"=\"xxxxxxxxxxxxxx\"; \"randomNumber\": 40884; \"temperature\": 23.80; \"humidity\": 65.00}",
"ttl": 60,
"published_at": "2021-07-03T08:24:31.981Z",
"coreid": "xxxxxxxx"
}
Request:
POST /api/v1//telemetry HTTP/1.1
Content-Type: application/json
Accept: application/json
User-Agent: ParticleBot/1.1 (https://docs.particle.io/webhooks)
host: myserver.net:8082
content-length: 123
Connection: keep-alive
It looks like the apiKey substitution is failing and returning an empty string. Any idea why? Is it the string escaping in the received JSON?
If I could get this working, rather than hardcode the API key in the device and have that sent in the JSON (which becomes published telemetry and has the potential to expose data if I’m not careful), it would be nice if I could put all this in the webhook. Is it possible to use variables within a webhook and do something like?:
apiKeys={
"BLE-Xen1": "xxxxxxxxxx",
"BLE-Xen6": "yyyyyyyyyy",
}
"url": "http://myserver.net:8082/api/v1/{{{apiKeys[{{{sensorName}}}]}}}/telemetry",