# Get Moderators 401 Error

**URL:** <https://discuss.dev.twitch.com/t/get-moderators-401-error/32011>\
**Category:** API\
**Created:** [June 5, 2021, 7:36pm UTC](https://discuss.dev.twitch.com/t/get-moderators-401-error/32011 "2021-06-05T19:36:19Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kev](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/kev/32/12442_2.png) [@Kev](https://discuss.dev.twitch.com/u/Kev)\
**Post date:** [June 5, 2021, 7:36pm UTC](https://discuss.dev.twitch.com/t/get-moderators-401-error/32011/1 "2021-06-05T19:36:19Z")

</div>

Hello everyone,

I’ve been trying to learn through the Twitch API docs the last few days, and I’ve hit a point where I’m struggling to retrieve a list of moderators. I’m getting a 401 / Unauthorized error, with an invalid oauth token error… I’ve tried both of the user access tokens, but I did notice on the docs it mentions:  
" `broadcaster_id` must match the `user_id` in the auth token. 1"

So does this mean that this GET request is limited to the broadcaster themselves, or is there a way to GET the broadcaster ID? If I wanted to get a list of Shroud’s mods… I wouldn’t have to have some sort of access ID from him would I?

Just to add, I have my Client-ID and Authorization headers, and I’ve been using postman to learn.

---

<div class="post-metadata">

**Author:** ![Dist](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/dist/32/7192_2.png) [@Dist](https://discuss.dev.twitch.com/u/Dist)\
**Post date:** [June 5, 2021, 8:09pm UTC](https://discuss.dev.twitch.com/t/get-moderators-401-error/32011/2 "2021-06-05T20:09:05Z")

</div>

> [@Kev](#):
>
> So does this mean that this GET request is limited to the broadcaster themselves, or is there a way to GET the broadcaster ID? If I wanted to get a list of Shroud’s mods… I wouldn’t have to have some sort of access ID from him would I?

If you wanted to get a list of Shourd’s mods, you would need Shroud to go through your apps OAuth flow, with the `moderation:read` scope, to grant you an access token that you can use to get the list of mods for his channel.

It’s the same for endpoints such as Get Broadcaster Subscriptions, you need the broadcaster themselves to grant you access to that data, you can’t use a token from your channel to access someone elses data that’s behind a scope.

---

<div class="post-metadata">

**Author:** ![Kev](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/kev/32/12442_2.png) [@Kev](https://discuss.dev.twitch.com/u/Kev)\
**Post date:** [June 5, 2021, 8:22pm UTC](https://discuss.dev.twitch.com/t/get-moderators-401-error/32011/3 "2021-06-05T20:22:20Z")

</div>

Ah okay, so if I wanted to have a web app that had access to that sort of thing, I could create a form where they put their ID and I do the rest in the script?

I guess I could just make some mods and my own channel and then try it that way. How long does the access token last?

---

<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:** [June 5, 2021, 10:55pm UTC](https://discuss.dev.twitch.com/t/get-moderators-401-error/32011/4 "2021-06-05T22:55:08Z")

</div>

Access Token duration is returned when you generate the token.

And can be fetched from the validate endpoint

> **[Authentication](https://dev.twitch.tv/docs/authentication/#validating-requests)**
>
> Authentication

---

<div class="post-metadata">

**Author:** ![Kev](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/kev/32/12442_2.png) [@Kev](https://discuss.dev.twitch.com/u/Kev)\
**Post date:** [June 7, 2021, 3:02am UTC](https://discuss.dev.twitch.com/t/get-moderators-401-error/32011/5 "2021-06-07T03:02:27Z")

</div>

So I set up a new twitch account to try and do this request on my own moderators, and I’m still receiving:

```
"error": "Unauthorized",
"status": 401,
"message": "Insufficient authorization in token"

```

I logged into my account, registered a new app, and sent this to get my Oauth token (I tried both implicit, and authorizatoin code flows), the request I sent was:

**[https://id.twitch.tv/oauth2/authorize?client\_id=rf1123pvpvqytve34c1qn67bij9u&redirect\_uri=http://localhost&response\_type=token&scope=moderation:read](https://id.twitch.tv/oauth2/authorize?client_id=rf1123pvpvqytve34c1qn67bij9u&redirect_uri=http://localhost&response_type=token&scope=moderation:read)**.

That’s not the actual client ID, but with this I received my token, and then sent my get moderators request like so:

 ![Screen Shot 2021-06-06 at 8.00.20 PM](https://d2opxh93rbxzdn.cloudfront.net/original/2X/f/f23cecee05e5a99dfb77eeb7f0d720532e7c0d31.png)

 ![Screen Shot 2021-06-06 at 8.01.30 PM](https://d2opxh93rbxzdn.cloudfront.net/original/2X/a/ae66eaee02d474cbbc8ad030cb630bfdd1bba57c.png)

Again the client ID and authorization are not the actual ones. If there’s anything I’m missing or more information please let me know, I really appreciate the active people on the twitch dev forums, there’s so much info and so much to learn!

---

<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:** [June 7, 2021, 3:44am UTC](https://discuss.dev.twitch.com/t/get-moderators-401-error/32011/6 "2021-06-07T03:44:32Z")

</div>

> [@Kev](#):
>
> That’s not the actual client ID

client ID’s are public, there is no need to redact your clientID.

> [@Kev](#):
>
> **[https://id.twitch.tv/oauth2/authorize?client\_id=rf1123pvpvqytve34c1qn67bij9u&redirect\_uri=http://localhost&response\_type=token&scope=moderation:read](https://id.twitch.tv/oauth2/authorize?client_id=rf1123pvpvqytve34c1qn67bij9u&redirect_uri=http://localhost&response_type=token&scope=moderation:read)**.

Did the oAuth prompt state that you were asking for the moderator read scope?

Here you seem not have URL encoded the redirect\_uri and might have got an unexpected result

You can call [Authentication | Twitch Developers](https://dev.twitch.tv/docs/authentication/#validating-requests) to check if the token has the needed scopes, is of type user, and has the user\_id `454325344`

> [@Kev](#):
>
> That’s not the actual client ID, but with this I received my token, and then sent my get moderators request like so:

Your postman call looks to have a bunch of extra headers, including cookies.

If that cookie is a Twitch cookie that might be interferring with the request. You are sending way more headers than is normal for an API call. Unlikely to be a problem but worth it to rule out.

---

<div class="post-metadata">

**Author:** ![Kev](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/kev/32/12442_2.png) [@Kev](https://discuss.dev.twitch.com/u/Kev)\
**Post date:** [June 7, 2021, 4:04am UTC](https://discuss.dev.twitch.com/t/get-moderators-401-error/32011/7 "2021-06-07T04:04:13Z")

</div>

Ah, thanks for showing me the validation request, I checked that out and realized my broadcaster ID was the same as the copy/pasted example!

I’m not sure what you mean by:

> Here you seem not have URL encoded the redirect\_uri and might have got an unexpected result

Is there something wrong with

> redirect\_uri=[http://localhost](http://localhost)

I just followed the docs and aren’t quite sure what url encoding is.

Thanks again, happy to make some progress today.

---

<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:** [June 7, 2021, 11:03am UTC](https://discuss.dev.twitch.com/t/get-moderators-401-error/32011/8 "2021-06-07T11:03:22Z")

</div>

> [@Kev](#):
>
> I just followed the docs and aren’t quite sure what url encoding is.

> **[HTML URL Encoding Reference](https://www.w3schools.com/tags/ref_urlencode.ASP)**
>
> W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more.

Without URLEncoding you could end up with a link as follows

`https://id.twitch.tv/oauth2/authorize?client_id=rf1123pvpvqytve34c1qn67bij9u&redirect_uri=http://localhost&response_type=token&scope=moderation:read`

Which says

| item | value |
| --- | --- |
| client\_id | rf1123pvpvqytve34c1qn67bij9u |
| redirect\_uri | `http://localhost&response_type=token&scope=moderation:read` |
| response\_type | none parsed |
| scope | none parsed |

Which would make an invalid link. and thus something else to check when having auth issues such as this

---

<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:** [July 7, 2021, 11:03am UTC](https://discuss.dev.twitch.com/t/get-moderators-401-error/32011/9 "2021-07-07T11:03:35Z")

</div>

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