# Management api token not working

**URL:** <https://community.auth0.com/t/management-api-token-not-working/107334>\
**Category:** Get Help\
**Tags:** actions-management-api, management-api\
**Created:** [May 18, 2023, 10:55pm UTC](https://community.auth0.com/t/management-api-token-not-working/107334 "2023-05-18T22:55:46Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![andyql](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/andyql/32/75461_2.png) [@andyql](https://community.auth0.com/u/andyql)\
**Post date:** [May 18, 2023, 10:55pm UTC](https://community.auth0.com/t/management-api-token-not-working/107334/1 "2023-05-18T22:55:46Z")

</div>

i’m gettting token following the official page: [Get Management API Access Tokens for Production](https://auth0.com/docs/secure/tokens/access-tokens/get-management-api-access-tokens-for-production)

```auto
   let obtainToken = {
        method: "POST",
        url: `https://${CLIENT_DOMAIN}/oauth/token`,
        headers: { "content-type": "application/x-www-form-urlencoded" },
        data: new URLSearchParams({
            grant_type: "client_credentials",
            client_id: CLIENT_ID,
            client_secret: CLIENT_SECRET,
            audience: `https://${CLIENT_DOMAIN}/api/v2/`,
        }),
    };

```

but this token is not working with

```auto
    let options = {
        method: "POST",
        url: `https://${CLIENT_DOMAIN}/api/v2/users/${userId}/roles`,
        headers: {
            "content-type": "application/json",
            authorization: `Bearer ${token}`,
            "cache-control": "no-cache",
        },
        data: { roles: [DEFAULT_ROLE_ID] },
    };

```

but the token from the dashboard works. not sure why.  
machine-machine is set and enabled. only thing don’t understand is that token obtained from api not working but only the token in dashboard works.

---

<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:** [May 18, 2023, 11:36pm UTC](https://community.auth0.com/t/management-api-token-not-working/107334/3 "2023-05-18T23:36:46Z")

</div>

Hey there @andyql welcome to the community!

Does the M2M application in your dashboard have the required permissions enabled? These are `read:users read:roles read:role_members`. You can set these by navigating to the M2M application → APIs → Management API:

 ![Screenshot 2023-05-18 at 4.36.11 PM](https://global.discourse-cdn.com/auth0/original/3X/c/7/c76267019f400929375c62074edbace13c5a0825.jpeg)

Keep us posted!

---

<div class="post-metadata">

**Author:** ![andyql](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/andyql/32/75461_2.png) [@andyql](https://community.auth0.com/u/andyql)\
**Post date:** [May 18, 2023, 11:43pm UTC](https://community.auth0.com/t/management-api-token-not-working/107334/4 "2023-05-18T23:43:25Z")

</div>

hey @ty.frith thanks for the reply. yes all the permission are ticked at this stage.

---

<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:** [May 18, 2023, 11:44pm UTC](https://community.auth0.com/t/management-api-token-not-working/107334/5 "2023-05-18T23:44:42Z")

</div>

No problem, happy to help!

Is there a particular error or status code you are getting? Does the token work if you cURL to get it?

```plaintext
  --url 'https://{yourDomain}/oauth/token' \
  --header 'content-type: application/x-www-form-urlencoded' \
  --data grant_type=client_credentials \
  --data 'client_id={yourClientId}' \
  --data 'client_secret={yourClientSecret}' \
  --data 'audience=https://{yourDomain}/api/v2/'
```

---

<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:** [May 18, 2023, 11:58pm UTC](https://community.auth0.com/t/management-api-token-not-working/107334/7 "2023-05-18T23:58:17Z")

</div>

Glad to hear it’s working as expected now!

> [@andyql](#):
>
> need to tick the `client_credentials` permissions. but the official doc didn’t mention these. so needs to update the doc i think.

Hmm I’m unaware of that requirement - Do you mind sharing which specific `client_credentials` permission(s)? That shouldn’t be required for the `/api/v2/users/${userId}/roles` as far as I know.

---

<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:** [June 2, 2023, 12:10am UTC](https://community.auth0.com/t/management-api-token-not-working/107334/9 "2023-06-02T00:10:01Z")

</div>

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