Basic Channel Details
Learn to fetch details of channels using the Twitch API.
Get channel information
Apart from a user's personal details, there also exists information that is specifically associated with their channel. We can send a GET request to the channels endpoint and retrieve the details of any channel we specify as a parameter.
The URL for this endpoint is as follows:
https://api.twitch.tv/helix/channels
All calls to this endpoint need to be authorized with either an app or a user access token. We'll use an app access token in this lesson.
Request parameters
We must provide a single query parameter to the endpoint to make a successful request. This endpoint doesn't support any optional parameters. The table below gives an overview of this parameter:
Parameter | Type | Category | Description |
| String | Required | This is the ID of the user whose channel details we want to fetch. We can provide a maximum of 100 IDs. |
Let's make a request to this endpoint using several different IDs from the table below:
Channel Name | ID |
Twitch | 12826 |
TwitchDev | 141981764 |
twitchgaming | 527115020 |
Let's paste these IDs one by one into the broadcaster_id
parameter on line 12 in the code below:
Note: If your token has expired, return to this lesson and follow the steps to generate a new one.
import fetch from "node-fetch";const endpointUrl = new URL("https://api.twitch.tv/helix/channels");const headerParameters = {Authorization: "Bearer {{APP_ACCESS_TOKEN}}","Client-Id": "{{CLIENT_ID}}",};// Specifying the channel we want to fetch details forconst queryParameters = new URLSearchParams({broadcaster_id: "{{USER_ID}}",});const options = {method: "GET",headers: headerParameters,};async function fetchChannelDetails() {try {endpointUrl.search = queryParameters;const response = await fetch(endpointUrl, options);printResponse(response);} catch (error) {printError(error);}}fetchChannelDetails();
In the code above, we perform the following:
Lines 11–13: We define the query parameters for the call using the
broadcaster_id
parameter.Lines 15–18: We set the options for the API call, specifying the HTTP request type as GET and providing the request headers.
Lines 20–28: We define a function called
fetchChannelDetails
to make a call to the channels endpoint.Lines 21–25: Within a
try
block, we provide the query parameters, make a call to the endpoint, and print the response from the API.Lines 25–27: We catch any errors or exceptions within a
catch
block and print them to the console.
Line 30: We invoke the
fetchChannelDetails
function.
Response fields
A successful response to a call to this endpoint is in the form of a JSON object with a single top-level property, data
. This property is an array of objects where each object represents a single channel. The complete details of the channel object are discussed in the table below:
Property | Type | Description |
| String | This is the ID of the channel user. |
| String | This is the channel user's login name. |
| String | This is the channel's display name. |
| String | This is an ISO-639-1 code for the language in which the user broadcasts. |
| String | This is the ID of the game currently being played on stream. If the channel is offline, this is the game that was played in the last stream. |
| String | This is the name of the game currently being played on stream. If the channel is offline, this is the game that was played in the last stream. |
| String | This is the title of the ongoing stream. If the channel is offline, this is the title of the latest stream. |
| Integer | This is the stream delay time in seconds. |
Get channel editors
Channels on Twitch may have other users besides the channel owner with edit rights. We can send a GET request to the Twitch API's channel editors endpoint and retrieve the list of users with edit permissions for a specified channel.
The URL for this endpoint is as follows:
https://api.twitch.tv/helix/channels/editors
All calls to this endpoint need to be authorized with a user access token that has the channel:read:editors
scope.
Request parameters
We must provide a single query parameter to make a successful request. It doesn't support any optional parameters. The table below gives an overview of this parameter:
Parameter | Type | Category | Description |
| String | Required | This is the ID of the user whose channel we want to fetch the list of editors for. It must be of the same user who is authenticated with the access token. |
Let's make a request to this endpoint and authenticate ourselves with a user access token.
Note: If your token has expired, return to this lesson and follow the steps to generate a new one.
import fetch from "node-fetch";const endpointUrl = new URL("https://api.twitch.tv/helix/channels/editors");const headerParameters = {Authorization: "Bearer {{USER_ACCESS_TOKEN}}","Client-Id": "{{CLIENT_ID}}",};// Specifying the channel we want to fetch the editor list forconst queryParameters = new URLSearchParams({broadcaster_id: "{{USER_ID}}",});const options = {method: "GET",headers: headerParameters,};async function fetchChannelEditors() {try {endpointUrl.search = queryParameters;const response = await fetch(endpointUrl, options);printResponse(response);} catch (error) {printError(error);}}fetchChannelEditors();
In the code above, we perform the following:
Lines 11–13: We define the query parameters for the call using the
broadcaster_id
parameter.Lines 15–18: We set the options for the API call, specifying the HTTP request type as GET and providing the request headers.
Lines 20–28: We define a function called
fetchChannelEditors
to make a call to the channel editors endpoint.Lines 21–25: Within a
try
block, we provide the query parameters, make a call to the endpoint, and print the response from the API.Lines 25–27: We catch any errors or exceptions within a
catch
block and print them to the console.
Line 30: We invoke the
fetchChannelEditors
function.
Note: If we have not added any editors to our channel, the response fields will be empty.
Response fields
A successful response to a call to this endpoint is in the form of a JSON object with a single top-level property, data
. This property is an array of objects where each object represents a single editor. The complete details of these objects are discussed in the table below:
Property | Type | Description |
| String | This is the ID of the editor. |
| String | This is the editor's display name. |
| String | This is the UTC timestamp of when the editor was given edit rights to the user's channel. |