# Unable to get access token via auth token API

**URL:** <https://community.auth0.com/t/unable-to-get-access-token-via-auth-token-api/167513>\
**Category:** Get Help\
**Tags:** clients, management-api\
**Created:** [January 5, 2025, 3:07pm UTC](https://community.auth0.com/t/unable-to-get-access-token-via-auth-token-api/167513 "2025-01-05T15:07:17Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![yohamta](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@yohamta](https://community.auth0.com/u/yohamta)\
**Post date:** [January 5, 2025, 3:07pm UTC](https://community.auth0.com/t/unable-to-get-access-token-via-auth-token-api/167513/1 "2025-01-05T15:07:18Z")

</div>

The auth0 API doesn’t work and I need help.

Postman script:

```json
const auth0Domain = pm.environment.get('AUTH0_DOMAIN');
const clientId = pm.environment.get('AUTH0_CLIENT_ID');
const clientSecret = pm.environment.get('AUTH0_CLIENT_SECRET');
const audience = pm.environment.get('AUTH0_AUDIENCE');

const tokenUrl = `https://${auth0Domain}/oauth/token`;
const username = pm.environment.get('USER_EMAIL');
const password = pm.environment.get('USER_PASSWORD');

console.log(
    {
        auth0Domain, clientId, clientSecret, audience, tokenUrl, username, password
    }
)

const getTokenRequest = {
  method: 'POST',
  url: tokenUrl,
  header: {
    'Content-Type': 'application/x-www-form-urlencoded'
  },
  body: {
    mode: 'urlencoded',
    urlencoded: [
      {key: 'grant_type', value: 'password'},
      {key: 'client_id', value: clientId},
      {key: 'client_secret', value: clientSecret},
      {key: 'username', value: username},
      {key: 'password', value: password},
      {key: 'audience', value: audience},
      {key: 'scope', value: 'openid profile email'}
    ]
  }
};

pm.sendRequest(getTokenRequest, (err, response) => {
  if (err) {
    console.error(err);
  } else {
    const jsonResponse = response.json();
    const newAccessToken = jsonResponse.access_token;
    pm.environment.set('ACCESS_TOKEN', newAccessToken);
    console.log('New access token set:', newAccessToken);
  }
});

```

error

```json
{"error":"invalid_request","error_description":"invalid audience specified for password grant exchange"}

```

Everything in auth0 are configured but the API doesn’t work. the tenant is configured exact same as different tenant where the script works. what is the thing could be wrong?

---

<div class="post-metadata">

**Author:** ![sumansaurav](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/sumansaurav/32/70627_2.png) [@sumansaurav](https://community.auth0.com/u/sumansaurav)\
**Post date:** [January 6, 2025, 3:17am UTC](https://community.auth0.com/t/unable-to-get-access-token-via-auth-token-api/167513/2 "2025-01-06T03:17:25Z")

</div>

Why are using even using password grant type?

---

<div class="post-metadata">

**Author:** ![marybeth.hunter](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/marybeth.hunter/32/61955_2.png) [@marybeth.hunter](https://community.auth0.com/u/marybeth.hunter)\
**Post date:** [January 6, 2025, 3:09pm UTC](https://community.auth0.com/t/unable-to-get-access-token-via-auth-token-api/167513/3 "2025-01-06T15:09:38Z")

</div>

Hi @yohamta,

Welcome to the Auth0 Community!

Can you check the `audience` and see if there is a trailing slash? Another Community member had a similar issue here: [Password grant for API via Android Lock - #3 by Yann](https://community.auth0.com/t/password-grant-for-api-via-android-lock/25214/3)

Thanks,

Mary Beth

---

<div class="post-metadata">

**Author:** ![yohamta](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@yohamta](https://community.auth0.com/u/yohamta)\
**Post date:** [January 6, 2025, 3:27pm UTC](https://community.auth0.com/t/unable-to-get-access-token-via-auth-token-api/167513/5 "2025-01-06T15:27:34Z")

</div>

Thanks a lot for your help. I have just delete and re-created API and Application and now everything works fine. BR,

---

<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:** [January 20, 2025, 3:27pm UTC](https://community.auth0.com/t/unable-to-get-access-token-via-auth-token-api/167513/6 "2025-01-20T15:27:40Z")

</div>

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