Start Channel Commercial

Hello, I’m trying to use the “Start Channel Commercial” API (Making for a partnered channel) I think this part is right but how do I add "-d ‘{“duration”: 30}’ " ?? Thanks :slight_smile:

> $channelsApi = 'https://api.twitch.tv/kraken/channels/12345678/commercial';
>  $ch = curl_init();
>  
>  curl_setopt_array($ch, array(
>     CURLOPT_HTTPHEADER => array(
>        "Client-ID: ababababababababababababa",
>        "Accept: application/vnd.twitchtv.v5+json",
>        "Content-Type: application/json",
>        "Authorization: OAuth ababababababababababababa",
>     ),
>     CURLOPT_RETURNTRANSFER => true,
>     CURLOPT_URL => $channelsApi
>  ));
>  
>  $response = curl_exec($ch);
>  curl_close($ch);
// ...
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => '{"duration": 30}',
// ...

Thanks (So does it go here?)

$channelsApi = ‘https://api.twitch.tv/kraken/channels/12345678/commercial’;
$ch = curl_init();

curl_setopt_array($ch, array(
CURLOPT_HTTPHEADER => array(
“Client-ID: ababababababababababababa”,
“Accept: application/vnd.twitchtv.v5+json”,
“Content-Type: application/json”,
“Authorization: OAuth ababababababababababababa”
),
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => ‘{“duration”: 30}’,
CURLOPT_URL => $channelsApi
));

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

I keep getting:

error: “Unauthorized”,
status: 401,
message: “Token invalid or missing required scope”

My OAuth has channel_editor or does the stream have to be live to give a positive response?

Can you try using the channel_commercial scope? That was the requirement prior to v5 so not sure if it changed or is an error in the docs.

Still not working… Even used both scopes…

Does the channel have to be live/is my code even right?

I did some further testing myself and channel_commercial is the correct scope. channel_editor alone will not work. (cc @DallasNChains error in the docs?) The channel does need to be live for the commercial to execute however you will get a different error indicating such:

{
  "error": "Unprocessable Entity",
  "status": 422,
  "message": "Commercials breaks are allowed every 8 min and only when you are online."
}

I copied your code replacing my Client-ID and OAuth token (with channel_commerical scope) and received the offline channel error instead of the token error you are receiving.

I would recommend double checking your OAuth token to make sure it has the correct scope: https://api.twitch.tv/kraken?oauth_token=

1 Like

Thank You… I have it working now :slight_smile:

Thanks, @george! I’ll update the docs. :slight_smile:

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