POST from PHP to IFTTT using cURL

Hi there. I am trying to access my bulb through IFTTT using a cURL POST request. I know I am making contact with my maker channel, as I get the response “Congratulations! You’ve fired the [myEvent] event” but my bulb does not update. When viewing the logs of my recipe in IFTTT all I get is this:

And here is my PHP cURL request

$url = 'https://maker.ifttt.com/trigger/trigger/[myEvent]/with/key/[myKey]';
$ch = curl_init($url);
$xml = 'value1=1&value2="kelvin:2500"';

curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);

$response = curl_exec($ch);
curl_close($ch);

Essentially I am trying to trigger my bulb via IFTTT programatically using PHP. If there is a better way to do this I am all ears. Thanks!

I can look at the logs on our end to see what happened but I need your LIFX account email. Could you PM it to me?

You’re working late! PM sent

Okay this one is a bit of a hairy one. The error our API is returning is:

Unable to parse color: 'kelvin:2500'

and the color that is getting sent in the request is:

color: "'kelvin:2500' brightness:1"

If you look there you can see that there are extra quotes. Either the issue is the extra double quotes you have in the curl (I don’t think those are actually required), or there are extra quotes in the advanced rule section of you rule. Any chance I could get a screenshot of the rule?

Yep, that’s done it. I was convinced that it needed that extra set of quotes for the sake of the colon in the $xml variable.

For posterity’s sake, here’s my PHP cURL request to IFTTT:

$url = 'https://maker.ifttt.com/trigger/[myEvent]/with/key/[myKey]';
$ch = curl_init($url);
$xml = "value1=0.5&value2=kelvin:2500";
echo $xml . "<br />";
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);

$response = curl_exec($ch);
curl_close($ch);

As for the gotchas, all characters are in lower case, and ‘value1’ (which is my brightness) needs to be a value between 0 and 1, doesn’t seem to matter whether or not it has a leading zero before the decimal point.

Thanks again Daniel, you’re the lifeblood of this developers forum!

1 Like