Modify User Details

Learn to update a user's description using the Twitch API.

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

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.

Press + to interact
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 set
const 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

id

String

This is the ID of the user.

login

String

This is the user's login name.

display_name

String

This is the user's display name.

type

String

This is the type of user. Its possible values are "staff""admin", and "global_mod". For users that fall under none of these types, this value is an empty string—"".

broadcaster_type

String

This is the user's broadcaster type. Its possible values are "partner" and "affiliate". For users that fall under none of these types, this value is an empty string—"".

description

String

This is the previous description that the user had set on their account.

profile_image_url

String

This is the static URL of the user's profile image.

offline_image_url

String

This is the static URL of the stream placeholder image that is displayed when the user is offline.

view_count

Integer

This is the total number of views that the user's channel has accumulated.

email

String

This is the user's verified email address. It's only included if we use a user access token with the user:read:email scope.

created_at

String

This is the UTC timestamp of when the user was created.