# Access\_denied when trying to access management api token

**URL:** <https://community.auth0.com/t/access-denied-when-trying-to-access-management-api-token/100951>\
**Category:** Get Help\
**Tags:** client-grants, management-api\
**Created:** [February 21, 2023, 4:19pm UTC](https://community.auth0.com/t/access-denied-when-trying-to-access-management-api-token/100951 "2023-02-21T16:19:15Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![cryogon](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/cryogon/32/44809_2.png) [@cryogon](https://community.auth0.com/u/cryogon)\
**Post date:** [February 21, 2023, 4:19pm UTC](https://community.auth0.com/t/access-denied-when-trying-to-access-management-api-token/100951/1 "2023-02-21T16:19:15Z")

</div>

When I am trying to get token with request it is working fine but when I am using axios it gives me error

```auto
const data = JSON.stringify({
  client_id: process.env.AUTH0_CLIENT_ID,
  client_secret: process.env.AUTH0_CLIENT_SECRET,
  audience: process.env.AUTH0_AUDIENCE,
  grant_type: "client_credentials",
});
const options = {
  method: "POST",
  url: "https://"+process.env.AUTH0_BASE_URL+"/oauth/token",
  headers: { "content-type": "application/json" },
  body: data,
};

```

when I run this code it works:

```auto
request(options, (err, response, body) => {
  if (err) {
    console.log(err);
  } else {
    console.log(JSON.parse(body));
  }
});

```

But when I run this it won’t

```auto
axios
  .request(options)
  .then((res) => {
    resolve(res);
  })
  .catch((err) => {
    console.log(err);
  });

```

Error:

```auto
data: { error: 'access_denied', error_description: 'Unauthorized' }

```

---

<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:** [February 22, 2023, 3:05am UTC](https://community.auth0.com/t/access-denied-when-trying-to-access-management-api-token/100951/3 "2023-02-22T03:05:20Z")

</div>

Hi there @cryogon welcome to the community!

I’m unfortunately not positive why that particular code isn’t working, it looks good to me 😕 Does the following work?

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

var options = {
  method: 'POST',
  url: 'https://{yourDomain}/oauth/token',
  headers: {'content-type': 'application/x-www-form-urlencoded'},
  data: new URLSearchParams({
    grant_type: 'client_credentials',
    client_id: '{yourClientId}',
    client_secret: '{yourClientSecret}',
    audience: 'https://{yourDomain}/api/v2/'
  })
};

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

```

Keep us posted!

---

<div class="post-metadata">

**Author:** ![cryogon](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/cryogon/32/44809_2.png) [@cryogon](https://community.auth0.com/u/cryogon)\
**Post date:** [February 22, 2023, 1:04pm UTC](https://community.auth0.com/t/access-denied-when-trying-to-access-management-api-token/100951/4 "2023-02-22T13:04:00Z")

</div>

Nope. It still doesn’t work

Edit:  
I could of keep using `request` but when I am hosting it on vercel as a serverless function it does not work and gives an unauthorized error. So I was thing maybe this can be fixed with `Axios`.

Another Edit:  
I switched to node-auth0 library and it works like request perfectly fine on localhost but on vercel it gives error

How should I use management api on vercel?

---

<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:** [February 22, 2023, 6:15pm UTC](https://community.auth0.com/t/access-denied-when-trying-to-access-management-api-token/100951/5 "2023-02-22T18:15:29Z")

</div>

Hey @cryogon thanks for following up!

Can you double check your `client_id` and `client_secret` in Vercel?

---

<div class="post-metadata">

**Author:** ![cryogon](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/cryogon/32/44809_2.png) [@cryogon](https://community.auth0.com/u/cryogon)\
**Post date:** [February 23, 2023, 3:05am UTC](https://community.auth0.com/t/access-denied-when-trying-to-access-management-api-token/100951/6 "2023-02-23T03:05:13Z")

</div>

Thanks for the reply @ty.frith.  
I have doublechecked the `client_id` and `client_secret` and It is the same as my local environment variables. I don’t know what could be causing this problem.

Edit:  
I think it has to be problem with environment variable on vercel when I hard coded value and deployed it on vercel it worked

---

<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:** [February 23, 2023, 11:10pm UTC](https://community.auth0.com/t/access-denied-when-trying-to-access-management-api-token/100951/7 "2023-02-23T23:10:52Z")

</div>

Thanks for the follow up @cryogon! I tend to agree as that’s typically the case in this sort of scenario 🤔

---

<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:** [March 9, 2023, 11:11pm UTC](https://community.auth0.com/t/access-denied-when-trying-to-access-management-api-token/100951/8 "2023-03-09T23:11:38Z")

</div>

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