Apparently I’m having a brain fail day - can someone please fix my code because I’m getting a ‘bad request, choices parameters missing’ response from Twitch. I’ve set it up in the same way I’ve done other CURL requests which require arrays within the main array but clearly I’ve missed something!
$choices = array('title' => 'Yes','title' => 'No');
$bodydata = array(
'broadcaster_id' => '501071947',
'title' => 'Can Kat ask for Shambos help?',
'choices' => $choices,
'channel_points_voting_enabled' => true,
'channel_points_per_vote' => 10,
'duration' => 120
);
$body = json_encode($bodydata);
$CCR = curl_init();
curl_setopt($CCR, CURLOPT_URL, "https://api.twitch.tv/helix/polls");
curl_setopt($CCR, CURLOPT_RETURNTRANSFER, true);
curl_setopt($CCR, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($CCR, CURLOPT_HTTPHEADER, array(
'Content-type: application/json',
'Authorization: Bearer '.$authtoken,
'Client-ID: '.$clientid,
));
curl_setopt($CCR, CURLOPT_POST,true);
curl_setopt($CCR, CURLOPT_POSTFIELDS,$body);
$polldata = json_decode(curl_exec($CCR),true);
curl_close($CCR);