Triggering a function with a URL

How would you call a function on a device using a URL instead of cURL? I want to call the settemp function with data that includes inputtemp=50. How would I end up doing this?


Because the Particle API requires a POST request to trigger a function you’d have to initiate that request somehow. You could setup a form on your website to achieve this but I’m not aware of any browsers that let you perform POST requests using the address bar alone

Basically, you don’t. Requesting variables is a GET request, which is what your browser does. Calling a function is a POST request, which your browser doesn’t do.
Some more threads on this (the search function does wonders ;)):

Some discussion about why calling a function from the browser doesn’t work/isn’t supposed to work:

A great tutorial on how to call functions from a website:

1 Like

@ardvark68 Everyone so far is correct, but I think it will help to explain POST vs GET a bit further.

###GET request
If you just wanted to read data from the Photon, like checking the value of a Spark.variable(), you are not attempting to modify it, just read it. HTTP standards have a specific type of request for this called GET. This is how typically every web page is requested. It is the standard type of request that is sent to a website when you enter a URL and press enter in your browser.

###POST request
You want to send a command to your Photon, so you are trying to in effect modify it or write to it. To comply with HTTP standards, that requires a POST type of request which sends extra data along with the URL. This is also the type of request that’s made when sending form data to a website. This requires special code to generate the POST request, and not something a browser will do just by typing in a URL and pressing enter.

###Particle Dev
In addition to the many links posted above, one simple way to send data to your settemp function is with Particle Dev. Check it out.