Curl returns "error":"Not Found"

curl does not seem to recognize the Photon device. I have uploaded a simple LED code to the Photon and have been able to turn it on via the Android Particle app. However, when attempting to post to the same function that turns on the LED using javascript, nothing happens. When trying to debug this using curl on my Windows 64 system, I get the following error:

C:\curl https://api.spark.io/v1/devices/3d002b000XXXXXXXXX/led -X PUT -d access_token=8510f8481bXXXXXXXXX -d params=on
{“ok”:false,“error”:“Not Found”}
C:\

I tried a few other commands I found on this forum including “ping” which seems to indicate it is not online, “online”:false, even though the Particle app is able to control the led parameter set to “on” or “off”.

C:\curl https://api.spark.io/v1/devices/3d002bXXXXXXXX/ping -X PUT -d access_token=8510f8481bXXXXXXXXXXX
{“online”:false,“ok”:true}
C:\

One curious thing that I do not see in any posts or in Simon Monk’s book is that the Web IDE link that reports the access code states that the access code is not valid for any products. I tried regenerating the access code, but each one says the same thing. I’m not sure what that’s about.

Any ideas on what I should try next?

When you want to call your Particle.function() you would POST not PUT.

The reference docs also show how a curl function call would be done correctly
https://docs.particle.io/reference/device-os/firmware/photon/#particle-function-


(the backslashes just denote line breaks, don’t put them in your command)

BTW, spark.io has been deprecated a while back - particle.io is what you want to use.
Hence the reference docs show the correct way to execute a ping like this
https://docs.particle.io/reference/device-cloud/api/#ping-a-device

2 Likes

Thanks for the quick reply!

I had wondered if spark.io had been deprecated. I’m new, and I really didn’t want to post without reading all the other posts. I’m also following along in a “Getting Started with the Photon” book. So, between all of that, I became confused a bit.

I will carefully read through the reference documents now. I actually had read some of them regarding access tokens, but again, that was a bit complicated involving setting up customer details and etc. none of which I thought was relevant.

By the way the book I’m reading recommends this bit of javascript to access the functions. Let me know if you see any deprecated elements as well:

var url = “https://api.particle.io/v1/devices/” + deviceID + “/led”;

function switchOn()
{
$.post(url, {params: “on”, access_token: accessToken });
}

function switchOff()
{
$.post(url, {params: “off”, access_token: accessToken });
}

Kudos to you “ScruffR”!

-robert

2 Likes

@ScruffR: BTW - sorry I didn’t mention, your example worked… and it took just a second to respond on the Photon… whereas my old code took forever to respond with the error, but that makes sense. Anyway, thank you again.

1 Like

Update on the above code snippet above. The lines with $.post in them just needed that params string changed to args as shown below:
$.post(url, {args: “on”, access_token: accessToken});

and in the function switchOff()
$.post(url, {args: “off”, access_token: accessToken});