Get user error javascript

This is code

function getUser(username) {
    return fetch(`https://api.twitch.tv/helix/users?login=${username}`, {
        method: "GET",
        headers: {
            'Client-ID': "csj7l3h1nqr7***********cen9",
            "Authorization": "Bearer pshj9**********mvgl1wfvfhko9e",
        }
    });
}

 await getUser(args[0]).then((res) => {
            if (res._total === 0) {
                return message.channel.send(new MessageEmbed().setColor(client.config.colors.Red).setDescription("You must specify **valid** a twitch username !"))
            } else {
                twitchID = res.users[0]._id
            }
        })

Result:

If you look at the documentation for Get Users https://dev.twitch.tv/docs/api/reference#get-users you’ll see that the response by Twitch is different from what you’re attempting to access. It looks like you’re using code based on the now removed v5 Kraken API, which is completely different from the current Helix API that you’re actually using.

For example, the response doesn’t have a _total field, nor an array called users, and the user doesn’t have a field _id.

To get the total number of results you’d need to look at the length of the data array, and the id of the first user in the response would be res.data[0].id

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.