# Unauthorized error when trying to get token from Management Api

**URL:** <https://community.auth0.com/t/unauthorized-error-when-trying-to-get-token-from-management-api/82167>\
**Category:** Get Help\
**Tags:** jwt\
**Created:** [April 21, 2022, 7:16pm UTC](https://community.auth0.com/t/unauthorized-error-when-trying-to-get-token-from-management-api/82167 "2022-04-21T19:16:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dchoi](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dchoi/32/34389_2.png) [@dchoi](https://community.auth0.com/u/dchoi)\
**Post date:** [April 21, 2022, 7:16pm UTC](https://community.auth0.com/t/unauthorized-error-when-trying-to-get-token-from-management-api/82167/1 "2022-04-21T19:16:40Z")

</div>

I am doing a rest call via axios to the management api. I have a m2m setup where my internal api service is needing a token to do mfa reset. I used the code that I found in the docs, [Get Management API Access Tokens for Production](https://auth0.com/docs/secure/tokens/access-tokens/get-management-api-access-tokens-for-production), but its giving me the given error. My api is authorized for the Management Api, it has the client\_grants enabled, and for other code I am able to use the ManagementClient object successfully. What could be the issue?

```auto
axios({
              method: "POST",
              url: `https://${AUTH0_DOMAIN}/oauth/token`,
              headers: {'content-type': 'application/x-www-form-urlencoded'},
              data: {
                grant_type: 'client_credentials',
                client_id: AUTH0_CLIENT_ID,
                client_secret: AUTH0_CLIENT_SECRET,
                audience: AUTH0_AUDIENCE
              }
            })

```

---

<div class="post-metadata">

**Author:** ![rueben.tiow](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rueben.tiow/32/11646_2.png) [@rueben.tiow](https://community.auth0.com/u/rueben.tiow)\
**Post date:** [April 21, 2022, 9:38pm UTC](https://community.auth0.com/t/unauthorized-error-when-trying-to-get-token-from-management-api/82167/3 "2022-04-21T21:38:26Z")

</div>

Hi @dchoi,

Thanks for reaching out to the Auth0 Community!

I understand you encountered issues trying to get a Management API token.

After looking closely at your code snippet, I found that you need to correct your `content-type` header from `application/x-www-form-urlencoded` to `application/json`.

For example:

```auto
var axios = require("axios").default;

var options = {
  method: 'POST',
  url: 'https://YOUR_DOMAIN/oauth/token',
  headers: {'content-type': 'application/json'},
  data: {
    grant_type: 'client_credentials',
    client_id: 'YOUR_CLIENT_ID',
    client_secret: 'YOUR_CLIENT_SECRET',
    audience: 'https://YOUR_DOMAIN/api/v2/'
  }
};

axios.request(options).then(function (response) {
  console.log(response.data);
}).catch(function (error) {
  console.error(error);
});

```

Once that is fixed, you can request an access token for the Management API.

Please let me know how this goes for you.

Thank you.

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [December 22, 2022, 10:51am UTC](https://community.auth0.com/t/unauthorized-error-when-trying-to-get-token-from-management-api/82167/4 "2022-12-22T10:51:02Z")

</div>


