Unauthorized error when trying to get token from Management Api

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, 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?

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
              }
            })

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:

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.