# 401 Error in Twitch API

**URL:** <https://discuss.dev.twitch.com/t/401-error-in-twitch-api/25298>\
**Category:** API\
**Created:** [May 1, 2020, 6:40pm UTC](https://discuss.dev.twitch.com/t/401-error-in-twitch-api/25298 "2020-05-01T18:40:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dj\_Expo](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/dj_expo/32/7914_2.png) [@Dj\_Expo](https://discuss.dev.twitch.com/u/Dj_Expo)\
**Post date:** [May 1, 2020, 6:40pm UTC](https://discuss.dev.twitch.com/t/401-error-in-twitch-api/25298/1 "2020-05-01T18:40:45Z")

</div>

Hello, this morning my code was working very well but now, i am getting 401 error.

 ![image](https://d2opxh93rbxzdn.cloudfront.net/original/2X/4/482b5e23785629bc77e9074c2058a27651f07a23.png)

This is the code:

```
const callAJAX = (props) => {
    const url = props.url,
        method = props.method || "GET",
        type = props.type || "JSON",
        header = props.header
    ;
    
    return new Promise(waitForResult => {
        const xhttp = new XMLHttpRequest();
        xhttp.onreadystatechange = function() {
            if (this.readyState === 4 && this.status === 200) {
                type === "text" 
                    ? waitForResult(this.response)
                    : waitForResult(JSON.parse(this.response))
                ;
            }
        };
		
        if (method === "GET") {
            xhttp.open("GET", url, true);
            for (const key in props.header) {
                xhttp.setRequestHeader(key, header[key]);
            }
            xhttp.send();
        }
    });
};

const AJAXProps = {
    url: "https://api.twitch.tv/helix/streams?first=20",
    header: {"Client-ID": "cpfxuznsjx64e2k6h58ujmmwtsqr29"}
};

var users = ["esl_csgo"];

var user_login = users.join('&user_login=');

    callAJAX(AJAXProps).then(allUser => {

        AJAXProps.url = `https://api.twitch.tv/helix/streams?user_login=${user_login}`;

        callAJAX(AJAXProps).then(onlineUsers => {
		
		console.log(onlineUsers);
		
		});
    });

```

Thank you

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [May 1, 2020, 6:42pm UTC](https://discuss.dev.twitch.com/t/401-error-in-twitch-api/25298/2 "2020-05-01T18:42:19Z")

</div>

You didn’t read

> [@Requiring OAuth for Helix Twitch API Endpoints](https://discuss.dev.twitch.com/t/requiring-oauth-for-helix-twitch-api-endpoints/23916):
>
> In an effort to standardize authentication and provide security improvements for the Twitch community, OAuth will soon be required for all Twitch API endpoints in the new Twitch API, also known as “Helix.” The goal of this announcement is to provide a timeline, full details of this new requirement, and answer a few anticipated questions. Please feel free to add further questions via the comments below and we appreciate your feedback during this process. Update (2020/06/02): See “How will this …

And/or the body reponse of your error

---

<div class="post-metadata">

**Author:** ![Dj\_Expo](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/dj_expo/32/7914_2.png) [@Dj\_Expo](https://discuss.dev.twitch.com/u/Dj_Expo)\
**Post date:** [May 1, 2020, 6:43pm UTC](https://discuss.dev.twitch.com/t/401-error-in-twitch-api/25298/3 "2020-05-01T18:43:25Z")

</div>

Oh, ok thank you

---

<div class="post-metadata">

**Author:** ![system](https://d2opxh93rbxzdn.cloudfront.net/original/2X/0/05909729875cce3b53e59d5561c4d23bb14948fc.png) [@system](https://discuss.dev.twitch.com/u/system)\
**Post date:** [May 31, 2020, 6:43pm UTC](https://discuss.dev.twitch.com/t/401-error-in-twitch-api/25298/4 "2020-05-31T18:43:30Z")

</div>

Closed on May 31, 2020, 6:43pm UTC

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