Publish/Subscribe and JSON data in events

@Dave & @bryce/@bwkahle : you guys are probably already aware of this & are best suited to answer.

A lot of IoT stuff we do passes mostly JSON around but I am having issues getting it to work using the Particle web hooks properly.

Ideally I would like to be able to use {{PARTICLE_EVENT_VALUE}} to grab the data (pre-formatted in escaped JSON by the Electron/Proton etc) and send it to a server by using an integration like:

{
“event”: “[[event_name]]”,
“url”: “[[SERVER]]”,
“requestType”: “POST”,
“mydevices”: true,
“body”: “{“device”: “{{PARTICLE_DEVICE_ID}}”, “timestamp”: “{{PARTICLE_PUBLISHED_AT}}”, “data”: {{PARTICLE_EVENT_VALUE}}}”
}

The reason I use “body” is because I have found a number of references around about it, but it does seem undocumented/deprecated. One of my sources of information is this github on particle webhooks

That github also mentions a lot about Mustache substitutions/conditionals and arrays. I could make a really complex object up using that I suppose but it basically ends up being a computational copy from source JSON into target JSON.

There are quite a few topics on this in the discussions board already but none seem to have a definitive answer:
Webhooks with JSON arrays or nested objects escaping quotes
Particle.publish and JSON escaped data
{{SPARK_EVENT_VALUE}} gets HTML encoded

Any update on this? is it possible/too much?

Hi @avsdev-cw,

So currently the event value is sent by default in the webhook body as “data”. So if you’re publishing a JSON string from your device, data will contain a string, and can be parsed at the destination server. It sounds like you’d like to instead send a parameter with the ‘raw’ JSON value, instead of it encapsulated in a string?

We have some tasks in the queue around making it easier to send native values instead of just strings, and I suspect that’ll help solve your use case. Unfortunately I don’t have a good idea of when those will be implemented, but I’ll bump that task and that should help it get pushed up the queue.

I’m happy to help answer webhook questions, but just a heads up that my colleague @bryce is no longer at Particle, so he might not respond on the forums.

Thanks!
David

1 Like