Formatting for Webhook

argon
Tags: #<Tag:0x00007fe22bd84108>

#1

I am attempting to send webhooks to tago.io with location data. Tago is receiving the raw data but the format is not valid for what they are expecting.

Particle is sending

{
    "location": "{'lat':45.913062,'lng':-121.014963}",
    "value": "Wildwood",
    "variable": "location"
}

Tago.io is expecting

{
    "location": {"lat":45.913062,"lng":-121.014975},
    "value": "Wildwood",
    "variable": "location"
}

The difference is only the location and format of the quotes. I have not been able to figure out how to adjust these quotes in Particle. Everything I attempt gives me syntax errors.

the code in question:

snprintf(pubbuf, sizeof(pubbuf), "{'lat':%f,'lng':%f}", gps.location.lat(), gps.location.lng());

#2

What syntax errors?
Have you tried "{\"lat\":%f, \"lng\":%f}" for the format string?
Also how have you got your webhook defined?


#3

raw data back in tago.io

{
    "location": "{\"lat\":45.913075,\"lng\":-121.014938}",
    "value": "Wildwood",
    "variable": "location"
}


#4

Try manually editing the JSON payload and removing the double quotes around {{{PARTICLE_EVENT_VALUE}}}