# Receiving 401 for "Bad audience" when attempting to get a user

**URL:** <https://community.auth0.com/t/receiving-401-for-bad-audience-when-attempting-to-get-a-user/109718>\
**Category:** Get Help\
**Tags:** users, management-api\
**Created:** [June 21, 2023, 9:13pm UTC](https://community.auth0.com/t/receiving-401-for-bad-audience-when-attempting-to-get-a-user/109718 "2023-06-21T21:13:04Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jakeb](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jakeb/32/48226_2.png) [@jakeb](https://community.auth0.com/u/jakeb)\
**Post date:** [June 21, 2023, 9:13pm UTC](https://community.auth0.com/t/receiving-401-for-bad-audience-when-attempting-to-get-a-user/109718/1 "2023-06-21T21:13:05Z")

</div>

I am creating a management API token using the following:

```javascript
            const client = new AuthenticationClient({
                domain: <string>this.configService.get('auth0.domain'),
                clientId: this.configService.get('auth0.managementClientId'),
                clientSecret: this.configService.get('auth0.managementClientSecret'),
            });

            const token = await client.clientCredentialsGrant({
                audience: '<audience>',
            });

```

and then attempting to request a user with this token with the following

```javascript
        const managementClient = new ManagementClient({
            domain: <string>this.configService.get('auth0.domain'),
            token: token.access_token,
            audience: '<audience>',
        });

        const auth0User = managementClient.getUser({
            id: authId,
        });

```

However, I receive the following error:

```json
{"statusCode":401,"error":"Unauthorized","message":"Bad audience: <audience>"}

```

The value of `<audience>` matches in all of the relevant locations, correctly matches the API identifier, and my server to server application has access to that API, so I’m really at a bit of a loss as to what is going on here

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [June 22, 2023, 5:18pm UTC](https://community.auth0.com/t/receiving-401-for-bad-audience-when-attempting-to-get-a-user/109718/3 "2023-06-22T17:18:11Z")

</div>

Hello @jakeb welcome to the community!

What audience are using? Do you mind sharing that here?

Thanks!

---

<div class="post-metadata">

**Author:** ![jakeb](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jakeb/32/48226_2.png) [@jakeb](https://community.auth0.com/u/jakeb)\
**Post date:** [June 22, 2023, 8:06pm UTC](https://community.auth0.com/t/receiving-401-for-bad-audience-when-attempting-to-get-a-user/109718/4 "2023-06-22T20:06:51Z")

</div>

Forgot to reply here, the issue was that I was using the audience for one of my custom APIs instead of the predefined system API, got that sorted already. Thanks though!

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [June 22, 2023, 9:00pm UTC](https://community.auth0.com/t/receiving-401-for-bad-audience-when-attempting-to-get-a-user/109718/5 "2023-06-22T21:00:28Z")

</div>

Great! That was my suspicion 🙂 Thanks for confirming with the community!

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [July 6, 2023, 9:00pm UTC](https://community.auth0.com/t/receiving-401-for-bad-audience-when-attempting-to-get-a-user/109718/6 "2023-07-06T21:00:42Z")

</div>

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