LIFX Developer Zone

Cycle endpoint not working


#1

I’ve been taking a look at the Cycle endpoint for the web API. I seem to be having issues with getting this to work however, even with the example JSON payload provided in the documentation failing with an unexpected validation reason: “states must have no less than 2 entries”

Entire JSON response object is:

{
  "error": "states must have no less than 2 entries",
  "errors": [
    {
      "field": "states",
      "message": [
        "must have no less than 2 entries"
      ]
    }
  ]
}

The JSON request payload I have been testing with is:

{
  "states": [
    {
      "brightness": 0.2,
      "color": "red"
    },
    {
      "brightness": 1
    },
    {
      "power": "off"
    }
  ],
  "defaults": {
    "power": "on",
    "duration": 2.0,
    "color": "kelvin:3500"
  }
}

Is there any reason that the API would not be seeing the state array members?


#2

Hello,

Are you sending Content-Type: application/json in your request?


#3

Yep that did it… seems a little obvious now, though I had tried ‘text/json’ without luck. May I suggest that the validation failure message for this is a little deceiving?

Curiously, the need for explicit Content-Type header does not appear to be in the API documentation, as far as I can tell? Perhaps this could be noted in there :slight_smile:

Thank you for the assist :slight_smile:


#4

No probs, I’ve faced the same problem in the past!

I’ve made a note to mention the Content-Type in the documentation somewhere.