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 = '';
>  $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_URL => $channelsApi
>  ));
>  $response = curl_exec($ch);
>  curl_close($ch);
// ...
CURLOPT_POSTFIELDS => '{"duration": 30}',
// ...

Thanks (So does it go here?)

$channelsApi = ‘’;
$ch = curl_init();

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

$response = curl_exec($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:

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.