Help with PHP cURL create custom rewards

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(
‘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 “

echo “
curl_setopt($CCR, CURLOPT_URL, "");
curl_setopt($CCR, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($CCR, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($CCR, CURLOPT_HTTPHEADER, array(  
    '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);

$output = json_decode($rewardresult);
echo "<pre>";
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) {
string(11) “Bad Request”
string(34) “Missing required parameter “title””
This is the part of the reference docs I’ve used as a basis for this:

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).

Your JSON header is wrong

Should be

curl_setopt($CCR, CURLOPT_HTTPHEADER, array(  
    'Content-type: application/json',
    'Authorization: Bearer '.$_SESSION['user_token'],
    'Client-ID: '.$_SESSION['client_id'],                                                            

Thats the only problem I can see

Tehnically this is wrong as true is not a valid bitmask for json_encode but doesn’t stop encoding working

1 Like

My absolute hero! Thank you - I missed that entirely (failed to tidy up from a previous failed attempt). This is what happens when you do something you’re not good at when extremely tired! I now know it needs 0’s instead of false and it’s bitching about incorrect channel scope, which is weird because I thought I’d set that up properly, but it’s major progress so again, thank you!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.