Modify Stream Schedules
Learn to update your Twitch stream schedule.
Set vacation details
The Twitch API allows us to update the settings of stream schedules. We send a PATCH request to the schedule settings endpoint of the API and set vacation details for our channel. We can set vacation details to specify a vacation period where all scheduled streams will be automatically canceled.
The URL for this endpoint is as follows:
https://api.twitch.tv/helix/schedule/settings
All calls to this endpoint must be authenticated with a user access token that has the channel:manage:schedule
scope.
Input parameters
This endpoint requires a single query parameter with a few other optional parameters. The table below gives an overview of these parameters:
Parameter | Type | Category | Description |
| String | Required | This is the ID of the user for whom we want to update the schedule settings. It must be of the same user who is authenticated with the access token. |
| Boolean | Optional | We set this to |
| String | Optional | This is an RFC3339 timestamp for the starting date of the vacation period. This parameter is required if |
| String | Optional | This is an RFC3339 timestamp for the ending date of the vacation period. This parameter is required if |
| String | Optional | This is the timezone in the IANA time zone database format. This parameter is required if |
Example call
Let's make a sample call to this endpoint, setting a vacation period of seven days, starting from today. We can update the timezone
parameter on line 15 to our timezone.
Note: If your token has expired, return to this lesson and follow the steps to generate a new one.
headers = {'Authorization' : 'Bearer {{USER_ACCESS_TOKEN}}','Client-Id' : '{{CLIENT_ID}}'}# Defining the vacation start and end datesstart = datetime.now() # Getting the current date/time for the start dateend = start + timedelta(days=7) # Setting the end date a week after the start dateparameters = {'broadcaster_id' : '{{USER_ID}}','is_vacation_enabled' : True,'vacation_start_time' : start.astimezone().isoformat(),'vacation_end_time' : end.astimezone().isoformat(),'timezone' : 'America/New_York'}response = requests.patch('https://api.twitch.tv/helix/schedule/settings',headers=headers, params=parameters)print(response.status_code)
The response from this request contains only an HTTP status code. If the API responds with 204
, the request is successful. If the request fails, it returns an error code instead. The table below gives a summary of these status codes:
Status Code | Description |
| This is a success code indicating the schedule settings were successfully updated. |
| This is an error code indicating that the request was invalid due to missing or invalid parameters. |
| This is an error code indicating that the API failed to authorize the request due to a missing bearer token or scopes. |
Update scheduled streams
What if we've already scheduled a stream and now want to change some of its details, such as the game we're playing or the stream title? To do so, we can send a PATCH request to the schedule segments endpoint.
All PATCH requests to this endpoint must be authenticated with a user access token that has the channel:manage:schedule
scope.
Input parameters
We must provide a couple of required query parameters and some optional body parameters to make a successful request. The table below discusses the details of these parameters:
Parameter | Parameter Type | Type | Category | Description |
| Query | String | Required | This is the ID of the user for whom we want to update the schedule settings. It must be the of the same user who is authenticated with the access token. |
| Query | String | Required | This is the ID of the segment we want to update. |
| Body | String | Optional | This is an RFC3339 timestamp for the starting time of the stream. |
| Body | String | Optional | This is the timezone in the IANA time zone database format. |
| Body | Boolean | Optional | This determines whether the scheduled stream is canceled. |
| Body | Integer | Optional | This is the duration of the stream in minutes. |
| Body | String | Optional | This is the ID of the game the streamer will play during the stream. |
| Body | String | Optional | This is the title of the stream. Its length cannot exceed 140 characters. |
Example call
Let's make a request to this endpoint to update the segment we've previously defined. We can try changing the value of the title
parameter on line 12 or add other parameters as per our liking.
Note: If your token has expired, return to this lesson and follow the steps to generate a new one.
headers = {'Authorization' : 'Bearer {{USER_ACCESS_TOKEN}}','Client-Id' : '{{CLIENT_ID}}'}parameters = {'broadcaster_id' : '{{USER_ID}}','id' : '{{SEGMENT_ID}}'}payload = {'title' : 'This title was changed by the API'}response = requests.patch('https://api.twitch.tv/helix/schedule/segment',headers=headers, params=parameters, json=payload).json()print(json.dumps(response, indent=4))
The response from this PATCH request is identical to the response we get upon sending a POST request to the schedule segments endpoint.
Delete scheduled streams
Twitch also allows us to delete scheduled segments using the API. To do so, we can send a DELETE request to the schedule segments endpoint. The request must be authenticated with a user access token that has the channel:manage:broadcast
scope.
Input parameters
This request requires only two query parameters that are discussed in the table below:
Parameter | Parameter Type | Type | Category | Description |
| Query | String | Required | This is the ID of the user for whom we want to update the schedule settings. It must be of the same user who is authenticated with the access token. |
| Query | String | Required | This is the ID of the segment we want to delete. |
Example call
Let's make a sample request to delete the segment we defined earlier.
Note: If your token has expired, return to this lesson and follow the steps to generate a new one.
headers = {'Authorization' : 'Bearer {{USER_ACCESS_TOKEN}}','Client-Id' : '{{CLIENT_ID}}'}parameters = {'broadcaster_id' : '{{USER_ID}}','id' : '{{SEGMENT_ID}}'}response = requests.delete('https://api.twitch.tv/helix/schedule/segment',headers=headers, params=parameters)print(response.status_code)
The response from this request is identical to the response we get from a PATCH request to the schedule settings endpoint.