Modify Channel Details
Learn to update the information of a channel using the Twitch API.
We'll cover the following
We might end up in situations where we have to update the information displayed on our channel page. The Twitch API allows us to do so using the channels endpoint through a simple PATCH request.
All PATCH requests to update a channel's information need to be authorized with a user access token that has the channel:manage:broadcast
scope.
Input parameters
To make a successful request, we need to provide the channel ID as a required query parameter. We can also pass some optional body parameters. The table below gives an overview of these parameters:
Parameter | Parameter Type | Type | Category | Description |
| Query | String | Required | This is the ID of the channel for which we want to update the details. |
| Body | String | Optional | This is the ID of the game currently being played on the stream. We can clear this value by passing |
| Body | String | Optional | This is an ISO-639-1 two-letter code for the language in which the channel broadcasts. Examples of its accepted values are |
| Body | String | Optional | This is the title of the last or current stream. This cannot be an empty string. |
| Body | Integer | Optional | This is the stream delay in seconds. Since it’s a Twitch Partner feature, normal users can’t update this value. |
Although all body parameters are listed as optional parameters, we must provide at least one of these parameters for the request to be valid.
Example call
Let's make a sample request to this endpoint, and authorize ourselves with a user access token that has the required scope. We can also change the parameters in, or add more parameters to, the payload
object starting on line 10 to values of 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}}'}payload = {'broadcaster_language' : 'other','game_id' : '509658' # Just Chatting}response = requests.patch('https://api.twitch.tv/helix/channels',headers=headers, params=parameters, json=payload)print(response)
Response structure
The response from this request only contains an HTTP status code. If the API responds with 204
, the request was successful. If the request fails, it returns an error code instead. The table below gives a brief summary of these status codes:
Status Code | Description |
| This is a success code indicating the details were successfully updated. |
| This is an error code indicating that the request was invalid due to missing or invalid parameters. This code is also returned if a non-partner user tries to update the |
| This is an error code indicating that the request failed due to server-side issues. |
Now that we've updated our channel details using the API, let's fetch our channel details once more to see whether the changes we made are reflected or not.
headers = {'Authorization' : 'Bearer {{APP_ACCESS_TOKEN}}','Client-Id' : '{{CLIENT_ID}}'}parameters = {'broadcaster_id' : '{{USER_ID}}'}response = requests.get('https://api.twitch.tv/helix/channels',headers=headers, params=parameters).json()print(json.dumps(response, indent=4))
If all goes smoothly, the changes we made in the previous request should reflect in the response to this request.