Modify User Details
Learn to update a user's description using the Twitch API.
We'll cover the following
Update user details
As users, we inevitably run into situations where we have to update our profile and details. The Twitch API allows us to do so using the users endpoint through a simple PUT request.
Currently, the API only allows us to update our account description through the API. However, other editable parameters may become available in the future.
All PUT requests to update a user's description need to be authorized with a user access token that has the user:edit
scope.
Request parameters
Since the API only gives us the ability to update the user's account description, there is only one query parameter that is discussed in the table below:
Parameter | Type | Category | Description |
| String | Optional | This is the new description that we want to add to the account. |
We can notice that the description
parameter is optional. If this parameter is not provided, no fields will be updated and no error will be returned.
Let's make a sample PUT request to this endpoint, authorizing ourselves with a user access token with the required scope and viewing the response. We can also change the value of the description
parameter on line 12 to any description of our liking.
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/users");const headerParameters = {Authorization: "Bearer {{USER_ACCESS_TOKEN}}","Client-Id": "{{CLIENT_ID}}",};// Defining the new description to be setconst queryParameters = new URLSearchParams({description: "Hello! I'm a learner on Educative!",});const options = {method: "PUT",headers: headerParameters,};async function updateUserDescription() {try {endpointUrl.search = queryParameters;const response = await fetch(endpointUrl, options);printResponse(response);} catch (error) {printError(error);}}updateUserDescription();
In the code above, we perform the following:
Lines 11–13: We define the query parameters for the call using the
description
parameter.Lines 15–18: We set the options for the API call, specifying the HTTP request type as PUT and providing the request headers.
Lines 20–28: We define a function called
updateUserDescription
to make a call to the users 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
updateUserDescription
function.
Response fields
The response from this request is the same as a GET request, with a single top-level property, namely data
, which contains an array of user objects. Since we can only update one user at a time, which is specified by the user access token, the data
array will always contain a single element.
Since the token we use has both the user:edit
and user:read:email
scopes, the response from the API includes the email
parameter. As a refresher, the table below gives an overview of the user object:
Property | Type | Description |
| String | This is the ID of the user. |
| String | This is the user's login name. |
| String | This is the user's display name. |
| String | This is the type of user. Its possible values are |
| String | This is the user's broadcaster type. Its possible values are |
| String | This is the previous description that the user had set on their account. |
| String | This is the static URL of the user's profile image. |
| String | This is the static URL of the stream placeholder image that is displayed when the user is offline. |
| Integer | This is the total number of views that the user's channel has accumulated. |
| String | This is the user's verified email address. It's only included if we use a user access token with the |
| String | This is the UTC timestamp of when the user was created. |