[FIXED] Php curl - new problem with Particle.function

This php code stopped to work this january with my Photon (maybe 'cause the new firmware ?).
The args value is no more passed to the function and command = null

If you switch to the html form (post) instead of php, the function works again and command = “SECRET_CODE”

Anyone can help ? Thank You !


$my_device = "xxxxxxxxxxxxxx";
$my_token = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
$url = "https://api.particle.io/v1/devices/".$my_device."/gate?access_token=".$my_token;
$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_POST, true);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt( $ch, CURLOPT_POSTFIELDS, array('args' => "SECRET_CODE"));
$response = curl_exec( $ch );
curl_close( $ch );


int gateOpen(String command) {
 Particle.publish("GATE", command);
1 Like

Try directing both the php code and the html form to a request bin and look at the logged requests. How do they differ?

fixed url-encoding the query string (but why this was not necessary before ?)

curl_setopt( $ch, CURLOPT_POSTFIELDS, http_build_query(array('args' => "SECRET_CODE")));

Thanks !

1 Like

Maybe you’ve never sent anything via PHP that required URL encoding before? Glad you found a solution.

The strange thing is that the initial code without http_build_query() worked until the end of last year…

So what’s changed ? :confused:

Perhaps it had to do with your payload? If you weren’t sending anything which needed to be URL encoded you are probably good with your old code. What happens if you just try sending the letter a using your old code? How about your new code? How do the requests differ?

I saw issues with sending functions recently too. In my case the code was Scala. Suddenly, url-encoding seems to be required (I had an unencoded “,” in my form parameter). It was an easy fix, but a little baffling at first.

Here the requests (SECRET_CODE is 20:02)



PHP CURL (without url-encoding)

Content-Disposition: form-data; name="args"


PHP CURL (with url-encoding)


Hi @elfugo

Is the colon new? The colon character (’:’) has special meaning in URLs and must be encoded.

Hi @bko ,
the SECRET_CODE is exactly the same as before, with the same colon char.

Interesting. Might be useful to page @Dave

Hey All!

Great question! We recently released an API update that included bringing some of our dependencies current. It’s entirely possible this upgrade had the unintended side effect of creating a need to url-encode arguments to function calls. I vaguely remember this was a problem a long time ago, and we fixed it so you could send special characters as particle function arguments.

I’ll ping the team on this and see what they find.


Thank you for this post, helped me in my project!