# API token using Javascript does not work but does in python

**URL:** <https://community.auth0.com/t/api-token-using-javascript-does-not-work-but-does-in-python/181483>\
**Category:** Get Help\
**Tags:** clients, management-api\
**Created:** [February 5, 2025, 2:31pm UTC](https://community.auth0.com/t/api-token-using-javascript-does-not-work-but-does-in-python/181483 "2025-02-05T14:31:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![nutri.kinetix.adm](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/nutri.kinetix.adm/32/70854_2.png) [@nutri.kinetix.adm](https://community.auth0.com/u/nutri.kinetix.adm)\
**Post date:** [February 5, 2025, 2:31pm UTC](https://community.auth0.com/t/api-token-using-javascript-does-not-work-but-does-in-python/181483/1 "2025-02-05T14:31:05Z")

</div>

I am having a strange issue when it comes to getting an authorization token. In my code I use axios typically but have done also tried it using request as given in the generated example when viewing it under Applications-\>APIs

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

var options = {
  method: 'POST',
  url: 'https://dev-8ciw43-h.us.auth0.com/oauth/token',
  headers: {'content-type': 'application/json'},
  data: {
    grant_type: 'client_credentials',
    client_id: 'xxxxx',
    client_secret: 'xxxxx',
    audience: 'https://dev-8ciw43-h.us.auth0.com/api/v2/'
  }
};

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

```

I get a 401 error when running this  
However if I use the same tool it works in python with no issues

I am trying to fix an app where someone hardcoded the token as a parameter.

---

<div class="post-metadata">

**Author:** ![nik.baleca](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/nik.baleca/32/68749_2.png) [@nik.baleca](https://community.auth0.com/u/nik.baleca)\
**Post date:** [February 5, 2025, 6:07pm UTC](https://community.auth0.com/t/api-token-using-javascript-does-not-work-but-does-in-python/181483/2 "2025-02-05T18:07:56Z")

</div>

Hi @nutri.kinetix.adm

Could you try the following and let me know if it works?

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

```

Kind Regards,  
Nik

---

<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:** [February 19, 2025, 6:08pm UTC](https://community.auth0.com/t/api-token-using-javascript-does-not-work-but-does-in-python/181483/4 "2025-02-19T18:08:28Z")

</div>

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