I’m trying to figure out how to channel rewards via a mysql database, and unfortunately I’m struggling so badly that I need to throw myself on the mercy of you all. Disclaimer, I am absolutely not a programmer. I started doing very basic php a few months ago and it’s been a hard struggle. In short, please don’t tell me how stupid and wrong I am, I know how stupid and wrong I am (I’ve been told over and over again - I’m just hoping you folks will be less brutal than Stack Overflow)!
Here’s my code:
$CCR = curl_init();
$rewardstring = array(
‘title’=>‘testreward’,
‘prompt’=>‘test’,
‘cost’ => ‘5’,
‘is_enabled’ => ‘false’,
‘background_color’ => ‘#FFFFFF’,
‘is_user_input_required’ => ‘false’,
‘is_max_per_stream_enabled’ => ‘false’,
‘max_per_stream’ => ‘false’,
‘is_max_per_user_per_stream_enabled’ => ‘false’,
‘max_per_user_per_stream’ => ‘false’,
‘is_global_cooldown_enabled’ => ‘false’,
‘global_cooldown_seconds’ => ‘false’,
‘should_redemptions_skip_request_queue’ => ‘false’
);
$reward = json_encode($rewardstring,true);
echo “
”;”;
var_dump($rewardstring);
var_dump($reward);
echo “
curl_setopt($CCR, CURLOPT_URL, "https://api.twitch.tv/helix/channel_points/custom_rewards?broadcaster_id=501071947");
curl_setopt($CCR, CURLOPT_RETURNTRANSFER, true);
curl_setopt($CCR, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($CCR, CURLOPT_HTTPHEADER, array(
'Content-type'=>'application/json',
'Authorization: Bearer '.$_SESSION['user_token'],
'Client-ID: '.$_SESSION['client_id'],
));
curl_setopt($CCR, CURLOPT_POST,true);
curl_setopt($CCR, CURLOPT_POSTFIELDS,$reward);
$rewardresult = curl_exec($CCR);
echo curl_error($CCR);
curl_close($CCR);
$output = json_decode($rewardresult);
echo "<pre>";
var_dump($output);
echo "</pre>";
I am getting a response from Twitch, my other scripts which use curl queries for fetching user, channel and stream data from Twitch are working so I know the auth token and client ID are good. What I can’t figure out is how to send the required data correctly to create a custom reward and I’m really stuck. This is the response I get:
object(stdClass)#4 (3) {
[“error”]=>
string(11) “Bad Request”
[“status”]=>
int(400)
[“message”]=>
string(34) “Missing required parameter “title””
}
This is the part of the reference docs I’ve used as a basis for this: https://dev.twitch.tv/docs/api/reference#create-custom-rewards
Please someone take pity on me. I’ve really tried, I’d never ask for help if I had any other option (cos I know how rightfully merciless programmers are with the lazy).