DEV Community

Discussion on: Automate Home Lights With The Fetch API

Collapse
delfick profile image
Stephen Moore

Hello,

I work in the Cloud team at LIFX

Cool article!

Just a couple notes, you can avoid needing the btoa function by telling the server to use the token as a Bearer. So you can say "Authorization: Bearer ${token}"

Also, there's multiple ways of specifying the colour as shown here api.developer.lifx.com/docs/colors

So, for example, if you want your lights to be a cool white you can say {"color": "kelvin:8000 saturation:0"} and that way you don't need to figure out the hex for that :)

Collapse
mtliendo profile image
Michael Liendo Author

Hey! Thanks so much for checking it out!

Yea, it's super nice to be able to use more specific colors it's just that color inputs give a hex value by default.

Would Bearer tokens be a simpler approach? I tried switching it over, but it said the token was no longer valid. I'm assuming because it's a raw token and not one given from an oAuth flow?

Thanks again for checking it out! I actually have 2 more posts coming up with fun projects around these lights, so if there's anything specific you'd like to see covered, my DM's are open on Twitter and I'd love to help out!

Collapse
delfick profile image
Stephen Moore

I'm not sure why your token wouldn't work as a Bearer token. If you get your token, can you do something like this from the command line?

curl http://api.lifx.co/v1/lights -H"Authorization: Bearer c6805af2e4fa8cd15dc28a8c6e54cc1c371e9efafb87b10536341105f74087a3"

(in this example, that's not a real token, but it looks like one :p)

The token you create from cloud.lifx.com never expires. The only way they stop working is if you revoke them from that same page.

I look forward to reading your other articles :)

Thread Thread
mtliendo profile image
Michael Liendo Author

Thanks so much, I got it to work with a Bearer token!

With Basic auth, it's token:, but I didn't need the colon for Bearer auth.

Thanks again, that definitely remotes some overhead!

Thread Thread
delfick profile image
Stephen Moore

Awesome! :)