Cannot "Set State/s, Cycle, Activate Scene" Outside of API Webpage Interface

Hi,

I have ran into a particular problem with using Set State, Set States, Cycle, Activate Scene.
It only seems to work on the webpage, but does not execute with POSTJSON.
(Working when I go to http://api.developer.lifx.com/docs/set-state & Fill in the values in “Try It Out”)

I can get the following to work on webpage and via https POST JSON:
Toggle Power
Breathe Effect
Pulse Effect

DO NOT WORK:
Set State
Set States
Cycle
Activate Scene
List Scenes
List Lights

Example of a working command (Pulse)

curl -k -H “Authorization: Bearer XXXX” -H “Content-Type: application/json” -X POST -d ‘{“color”:“Blue”,“from_color”:“Green”,“period”:0.5,“cycles”:10,“persist”:false,“power_on”:true,“peak”:".25"}’ “https://api.lifx.com/v1/lights/label:XXX/effects/pulse

Example of a NON WORKING commands (Set State, Activate Scene & List Scene)

curl -k -H “Authorization: Bearer XXXX” -H “Content-Type: application/json” -X POST -d ‘{“power”:“on”,“color”:“Red”,“brightness”:1,“duration”:2}’ “https://api.lifx.com/v1/lights/all/state
(I have also tried changing selector to “label:XXX” and “all”, still does not work)

curl -k -H “Authorization: Bearer XXXX” -H “Content-Type: application/json” -X POST -d ‘{“duration”:5}’ “https://api.lifx.com/v1/scenes/scene_id:XXX/activate

curl -k -H “Authorization: Bearer XXXX” -H “Content-Type: application/json” -X POST -d ‘{}’ “https://api.lifx.com/v1/scenes

I get a 404 error for all.

Can anyone point me to the right direction on how I can get all commands to work just like they work on the API “Try It Out” webpages.

I can’t answer your question directly, but if you open your browser’s developer tools and submit a working request you should be able to see precisely what is being sent by the browser - Chrome for example has excellent tools for this, and Firefox tools are pretty decent too.

Okay I will try to see what it is sending. What am I looking for? Anything in particular?

(Plus the webpage results are fine and it works on it. It’s only not working when the set state etc. is sent via curl command.)

Check the headers and request body to make sure you’re sending the same thing via curl.

You’re very close. You just need to set the correct HTTP Method (Eg: PUT) for each endpoint.

For example, the /v1/lights/:selector/state endpoint only accepts PUT requests. If you make a POST request to this URL you’ll get a 404 - Not found because that endpoint doesn’t exist. The HTTP Method + URL make the signature of the endpoint.

curl -k -H "Authorization: Bearer XXXX" -H "Content-Type: application/json" -X PUT -d '{"power":"on","color":"Red","brightness":1,"duration":2}' "https://api.lifx.com/v1/lights/all/state"

Give extra attention to the HTTP Method in the documentation. Each endpoint specifies which HTTP Method to use.

In the future we may consider returning a 405 - Method not allowed if the URL exists, but the HTTP Method is incorrect to give a better clue about what’s going on.