Trying to get some basic PHP code running, but have hit a curious problem with the toggle lights function. It works if I use the curl command directly e.g.
curl -X POST “https://api.lifx.com/v1/lights/group:Study/toggle” -H “Authorization: Bearer c…9” -d “duration=1.0”
or the example on the docs page.
My initial PHP code was (based on the example page and other sports here):
<?php $link = "https://api.lifx.com/v1/lights/group:Study/toggle"; $authToken = "c...........9"; $ch = curl_init($link); $headers = array('Authorization: Bearer ' . $authToken); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_POST, true); $response = curl_exec($ch); ?>But this gives me a ‘400 Bad Request’ error
If I include duration data,e.g.
<?php $link = "https://api.lifx.com/v1/lights/group:Study/toggle"; $authToken = "c..........9"; $ch = curl_init($link); $headers = array('Authorization: Bearer ' . $authToken); $data = 'duration=1.0' curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_POST, true); $response = curl_exec($ch); ?>there is no error reported, but no response from the light(s) or in the browser. I’ve tried various :selector values (even ‘all’) and the behaviour is consistent.
Feel I must be missing something obvious, but it’s eluded me so far…