How to Use Twitch Api to Delete Schedule Segment

Table of Contents

To delete a scheduled segment using the Twitch API from within a WordPress plugin or theme, you can use the wp_remote_request() function to send an HTTP DELETE request to the /scheduled_broadcasts endpoint.

Here’s an example of how you can do this:

Copy code<?php

// Replace YOUR_CLIENT_ID and YOUR_TOKEN with your own client ID and OAuth token
$clientId = 'YOUR_CLIENT_ID';
$token = 'YOUR_TOKEN';

// Set the ID of the scheduled segment that you want to delete
$scheduledSegmentId = '12345';

// Set the headers for the request
$headers = [
  'Client-ID' => $clientId,
  'Authorization' => 'Bearer ' . $token
];

// Send the DELETE request to the /scheduled_broadcasts endpoint
$response = wp_remote_request(
  'https://api.twitch.tv/helix/scheduled_broadcasts/' . $scheduledSegmentId,
  [
    'method' => 'DELETE',
    'headers' => $headers,
  ]
);

// Check the status code of the response to see if the request was successful
if (wp_remote_retrieve_response_code($response) == 204) {
  echo 'Scheduled segment deleted successfully!';
} else {
  echo 'Error deleting scheduled segment: ' . wp_remote_retrieve_response_code($response);
}

Keep in mind that you will need to have a valid OAuth token with the channel:edit:broadcast scope to be able to delete a scheduled segment using the Twitch API. You can learn more about authenticating with the Twitch API and obtaining OAuth tokens in the Twitch API documentation.

Scroll to Top

Twitcher will be launched on november.

But you can participate as beta tester. Let us your mail and help us to create the best Wordpress Plugin for streamers ever.