Socket API doesn't accept JSON in Data payload

The Socket API doesn’t accept any JSON in Data and I am unable to use the JSON fields in any Route payloads. These messages make it to the data router but it doesn’t recognize the data/json.

Example socket API message
{“devicekey”:"!SecretKey",“data”:{“state”:“home”}, “tags”:“ha_location”}

If I can’t put JSON as data in a message and use that as variables in Route Payloads then i’m going to have to find another platform that supports this. Other than single string messages there isn’t really a point in the socket API…

If I could at least just use the entire data JSON and pass that through an advanced webhook that would work for me. I dont necessarily need to use each part as variables. I can’t do anything with the json data at all.

1 Like

Just tested this on my end, also not working, even when enclosed in parenthesis like below
{"k":"keygoeshere","d":"{"Lat":"###.######", "Long":"-###.######","Alt":"139.50","Heading":"90","Sats": "9"}","t":"GPS"}

Ok, further testing is showing me that it’s having issues parsing because of the double quotes. I don’t know how to get around that… I can try adding an extra escape character (like {"k":"keygoeshere","d":"{\"Lat\":\"###.######\", \"Long\":\"-###.######\",\"Alt\":\"139.50\",\"Heading\":\"90\",\"Sats\": \"9\"}","t":"GPS"})

Edit:
Wow, that actually worked. Setting my string to

content = "{\\\"Lat\\\":\\\"" + String(gpsdata.lat, 6) + "\\\", \\\"Long\\\":\\\"" + String(gpsdata.lng, 6) + "\\\",\\\"Alt\\\":\\\"" + String(gpsdata.alt) + "\\\",\\\"Heading\\\":\\\"" + String(gpsdata.heading) + "\\\",\\\"Sats\\\": \\\"" + String(gpsdata.sat) + "\\\"}";

which sends as

{"k":"keygoeshere","d":"{\"Lat\":\"###.######\", \"Long\":\"-###.######\",\"Alt\":\"134.50\",\"Heading\":\"165\",\"Sats\": \"10\"}","t":"GPS"}

and comes up as

1 Like

Wow, I never would have thought of that. Thanks!

This should be in their Socket API documentation.