Cloud API Particle Publish passing JSON?

Hi!
I’ve just started playing with my Particle Photon.
I have been able to fire an event from curl and successfully subscribed to it over on the photon (using this documentation
I’ve been here: https://docs.particle.io/reference/api/#publish-an-event).

This is great, except what i would really like to do is call the publish api method and pass data to it using JSON rather than the additional url parameters. Is that possible?

E.g.
Instead of doing an HTML POST to this url:
https://api.particle.io/v1/devices/events -d “name=my_event_name” -d “data=Hello World” -d “private=false” -d “ttl=60” -d access_token=xyz

Do something like this:
POST to https://api.particle.io/v1/devices/events -d access_token=xyz
with a JSON body of something like this:
{
“name”:“my_event_name”,
“data”:“Hello World”,
“private”:false,
“ttl”:60
}

The webhook that i’m going to eventually use to trigger this doesn’t allow me to put parameters into the URL, rather it just lets me populate them into a JSON body. If need be i can write my own web api to accept the JSON and then translate that into the url style that works… but just curious if that was my only option.
Thanks in advance!
Darren

Hello,

Let me ping someone that might be able to help, @Dave are you able to assist?

Kyle

That certainly works (not sure if that’s the exact syntax is correct, but that’s the gist of it. Those cURL parameters are nothing more than parts of the HTML request.

This topics is a nice tutorial about connecting with the API using HTML requests:

For tinkering, I can also suggest Postman to easily play around with requests (it also generates the necessary code for you then :))

Thanks for the tips guys, I really appreciate it.
I was using Postman and was unable to get that to work - until i found that the curl -d values get put into the http request in the format of “application/x-www-form-urlencoded”. At this point i was able to use Postman (by changing the body type to application/x-www-form-urlencoded instead of application/json.
A little more investigation lead me to here: http://stackoverflow.com/questions/14551194/how-are-parameters-sent-in-an-http-post-request - which all in all seems to be confirming that I cannot simply post the data as JSON.

So my in-progress-solution is that i’ve created my own Web API POST method that accepts the JSON format that my external webhook can create… within the method i parse out the JSON and build up “application/x-www-form-urlencoded” http POST over to the Particle Cloud.

Thanks again for your help, I’m brand new to the Photon and have been having way too much fun with it this week :slight_smile: