# Getting 401 when sending the access token request for the mangement api

**URL:** <https://community.auth0.com/t/getting-401-when-sending-the-access-token-request-for-the-mangement-api/105376>\
**Category:** Get Help\
**Tags:** users, management-api\
**Created:** [April 24, 2023, 12:19pm UTC](https://community.auth0.com/t/getting-401-when-sending-the-access-token-request-for-the-mangement-api/105376 "2023-04-24T12:19:30Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![adhamdoody7813](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/adhamdoody7813/32/45544_2.png) [@adhamdoody7813](https://community.auth0.com/u/adhamdoody7813)\
**Post date:** [April 24, 2023, 12:19pm UTC](https://community.auth0.com/t/getting-401-when-sending-the-access-token-request-for-the-mangement-api/105376/1 "2023-04-24T12:19:30Z")

</div>

i wanted to extract the metadata for my next js blog app when i looked through the docs it says u can get it via the ` auth0 management Api` i followed the docs here [Get Management API Access Tokens for Production](https://auth0.com/docs/secure/tokens/access-tokens/get-management-api-access-tokens-for-production) when i send the post request to get the access token to be able to use the managment Api

```auto
const options = {
 method: 'POST',
 url: 'https://{myDomain}/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://{audience}/api/v2/'
 })
};

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

```

i get this error in the console

 ![2023-04-24 14-16-58](https://global.discourse-cdn.com/auth0/original/3X/0/e/0ea3784d45bff33cab32001d6128f64e2bfb891b.png)

---

<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 25, 2023, 3:04am UTC](https://community.auth0.com/t/getting-401-when-sending-the-access-token-request-for-the-mangement-api/105376/3 "2023-04-25T03:04:03Z")

</div>

Hi @adhamdoody7813,

Thanks for reaching out to the Auth0 Community!

After looking through your code snippet, it seems like the error is derived from the `headers`.

When testing this locally on my machine, I got it working with the following code snippet:

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

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

```

Could you please try the code above and let me know how it works for you?

Thanks,  
Rueben

---

<div class="post-metadata">

**Author:** ![adhamdoody7813](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/adhamdoody7813/32/45544_2.png) [@adhamdoody7813](https://community.auth0.com/u/adhamdoody7813)\
**Post date:** [April 25, 2023, 6:02am UTC](https://community.auth0.com/t/getting-401-when-sending-the-access-token-request-for-the-mangement-api/105376/4 "2023-04-25T06:02:20Z")

</div>

@rueben.tiow i have made the changes as u mentioned but now i get this

 ![2023-04-25 08-01-33](https://global.discourse-cdn.com/auth0/original/3X/7/e/7e7f10572857b4add0e7d6d1f49512e713861e9b.png) keep in mind that i got the  
header` {'content-type': 'application/x-www-form-urlencoded'}` from the docs

---

<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:** [May 1, 2023, 7:49pm UTC](https://community.auth0.com/t/getting-401-when-sending-the-access-token-request-for-the-mangement-api/105376/5 "2023-05-01T19:49:14Z")

</div>

Hi @adhamdoody7813,

Thank you for your response.

It seems like you are making a request from the frontend client instead of the backend server, which throws the “blocked by CORS policy” error.

Given that, I recommend that you make the request on the backend to get the Management API’s Access Token.

When testing on my side, I used Postman to get a Management API access token.

Please let me know how this goes.

Thanks,  
Rueben

---

<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:** [August 31, 2023, 12:25am UTC](https://community.auth0.com/t/getting-401-when-sending-the-access-token-request-for-the-mangement-api/105376/6 "2023-08-31T00:25:02Z")

</div>

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