# Problem getting access\_token from /oauth/token End-Point (Payload)

**URL:** <https://community.auth0.com/t/problem-getting-access-token-from-oauth-token-end-point-payload/116672>\
**Category:** Get Help\
**Tags:** other, community-topic\
**Created:** [September 20, 2023, 3:32am UTC](https://community.auth0.com/t/problem-getting-access-token-from-oauth-token-end-point-payload/116672 "2023-09-20T03:32:01Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![brokerx](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/brokerx/32/50582_2.png) [@brokerx](https://community.auth0.com/u/brokerx)\
**Post date:** [September 20, 2023, 3:32am UTC](https://community.auth0.com/t/problem-getting-access-token-from-oauth-token-end-point-payload/116672/1 "2023-09-20T03:32:01Z")

</div>

Newbie here…

Using Next13 (nextJS) and wrote something that calls the /oauth/token endpoint; I’m trying to obtain an access\_token in order to make some subsequent calls once a user is logged in.

I have everything working fine in Postman; get payload back fine and see it.

{  
“access\_token”: “eyJhbGciOiJSUzI1NiIsInR5cCI6IkpX…”,  
“scope”: “read:users update:users delete:users create:users read:users\_app\_metadata update:users\_app\_metadata delete:users\_app\_metadata create:users\_app\_metadata read:logs\_users read:roles create:roles update:roles create:role\_members client\_credentials”,  
“expires\_in”: 86400,  
“token\_type”: “Bearer”  
}

When I make the exact same call in the app I get a 200, it works fine, however, I see this as the body:

```
body: { stream: undefined }

```

I’m not sure how/where I get the access\_token from this payload?

I’m clearly missing something very basic/easy.

Thanks

---

<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:** [September 20, 2023, 5:24pm UTC](https://community.auth0.com/t/problem-getting-access-token-from-oauth-token-end-point-payload/116672/2 "2023-09-20T17:24:41Z")

</div>

Hey @brokerx welcome to the community!

> [@brokerx](#):
>
> I’m not sure how/where I get the access\_token from this payload?
> 
> I’m clearly missing something very basic/easy.

It’s hard to know for sure, but just to clarify, it sounds/looks like you’re trying to get a [Management API access token](https://auth0.com/docs/secure/tokens/access-tokens/management-api-access-tokens) as opposed to a user access token?

---

<div class="post-metadata">

**Author:** ![brokerx](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/brokerx/32/50582_2.png) [@brokerx](https://community.auth0.com/u/brokerx)\
**Post date:** [September 20, 2023, 5:37pm UTC](https://community.auth0.com/t/problem-getting-access-token-from-oauth-token-end-point-payload/116672/3 "2023-09-20T17:37:26Z")

</div>

Hi - correct, Management API access token.

---

<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:** [September 20, 2023, 5:52pm UTC](https://community.auth0.com/t/problem-getting-access-token-from-oauth-token-end-point-payload/116672/4 "2023-09-20T17:52:08Z")

</div>

Gotcha, thanks for clarifying! Are you using a particular library to make the http request? I most often see `axios` - A function might look like:

```auto
const axios = require('axios');

async function getManagementApiToken() {
  const data = {
    client_id: process.env.AUTH0_MANAGEMENT_API_CLIENT_ID,
    client_secret: process.env.AUTH0_MANAGEMENT_API_CLIENT_SECRET,
    audience: process.env.AUTH0_AUDIENCE,
    grant_type: 'client_credentials'
  };

  try {
    const response = await axios.post(`https://${process.env.AUTH0_DOMAIN}/oauth/token`, data);
    return response.data.access_token;
  } catch (error) {
    console.error('Error getting Auth0 Management API Token:', error);
    throw error;
  }
}

```

---

<div class="post-metadata">

**Author:** ![brokerx](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/brokerx/32/50582_2.png) [@brokerx](https://community.auth0.com/u/brokerx)\
**Post date:** [September 20, 2023, 6:13pm UTC](https://community.auth0.com/t/problem-getting-access-token-from-oauth-token-end-point-payload/116672/5 "2023-09-20T18:13:08Z")

</div>

Cool, ya was just using fetch…

export async function GetAuth0AccessToken() {

```
const url = `${process.env.AUTH0_ISSUER_BASE_URL}` + "/oauth/token";

const payload = {
    "grant_type" : "client_credentials",
    "client_id" : `${process.env.AUTH0_CLIENT_TOKEN_ID}`,
    "client_secret" : `${process.env.AUTH0_CLIENT_TOKEN_SECRET}`,
    "audience" : `${process.env.AUTH0_CLIENT_AUDIENCE}`
}

const headers = {   
    'content-type' : 'application/json'
}

try {
    const response = await fetch(url, {
      method: 'POST',
      headers,
      body: JSON.stringify(payload),
    });

    if (response.ok) {
      console.log(response)
    } else {
      const errorData = await response.text();
      console.log(errorData)
    }
  } catch (error) {
    console.log('Internal Server Error')
  }

```

}

**Payload I get back:**

Response {  
[Symbol(realm)]: null,  
[Symbol(state)]: {  
aborted: false,  
rangeRequested: false,  
timingAllowPassed: true,  
requestIncludesCredentials: true,  
type: ‘default’,  
status: 200,  
timingInfo: {  
startTime: 1217396.2971999645,  
redirectStartTime: 0,  
redirectEndTime: 0,  
postRedirectStartTime: 1217396.2971999645,  
finalServiceWorkerStartTime: 0,  
finalNetworkResponseStartTime: 0,  
finalNetworkRequestStartTime: 0,  
endTime: 0,  
encodedBodySize: 2,  
decodedBodySize: 0,  
finalConnectionTimingInfo: null  
},  
cacheState: ‘’,  
statusText: ‘OK’,  
headersList: HeadersList {  
cookies: [Array],  
[Symbol(headers map)]: [Map],  
[Symbol(headers map sorted)]: null  
},  
urlList: [[URL] ],  
**body: { stream: undefined }**  
},  
[Symbol(headers)]: HeadersList {  
cookies: [  
‘did=s%3Av0%3Ad9beb930-57e0-11ee-bc39-3903e846145d.GOfR8UnQKK%2FSbYMQPKTHOZqj1X5i%2FLmCY2s%2BcfYcw3U; Max-Age=31557600; Path=/; Expires=Fri, 20 Sep 2024 00:09:33 GMT; HttpOnly; Secure; SameSite=None’,  
‘did\_compat=s%3Av0%3Ad9beb930-57e0-11ee-bc39-3903e846145d.GOfR8UnQKK%2FSbYMQPKTHOZqj1X5i%2FLmCY2s%2BcfYcw3U; Max-Age=31557600; Path=/; Expires=Fri, 20 Sep 2024 00:09:33 GMT; HttpOnly; Secure’  
],  
[Symbol(headers map)]: Map(25) {  
‘date’ =\> [Object],  
‘content-type’ =\> [Object],  
‘transfer-encoding’ =\> [Object],  
‘connection’ =\> [Object],  
‘cf-ray’ =\> [Object],  
‘cf-cache-status’ =\> [Object],  
‘cache-control’ =\> [Object],  
‘set-cookie’ =\> [Object],  
‘strict-transport-security’ =\> [Object],  
‘vary’ =\> [Object],  
‘ot-baggage-auth0-request-id’ =\> [Object],  
‘ot-tracer-sampled’ =\> [Object],  
‘ot-tracer-spanid’ =\> [Object],  
‘ot-tracer-traceid’ =\> [Object],  
‘pragma’ =\> [Object],  
‘traceparent’ =\> [Object],  
‘tracestate’ =\> [Object],  
‘x-auth0-requestid’ =\> [Object],  
‘x-content-type-options’ =\> [Object],  
‘x-ratelimit-limit’ =\> [Object],  
‘x-ratelimit-remaining’ =\> [Object],  
‘x-ratelimit-reset’ =\> [Object],  
‘server’ =\> [Object],  
‘content-encoding’ =\> [Object],  
‘alt-svc’ =\> [Object]  
},  
[Symbol(headers map sorted)]: null  
}  
}

---

<div class="post-metadata">

**Author:** ![brokerx](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/brokerx/32/50582_2.png) [@brokerx](https://community.auth0.com/u/brokerx)\
**Post date:** [September 20, 2023, 9:28pm UTC](https://community.auth0.com/t/problem-getting-access-token-from-oauth-token-end-point-payload/116672/6 "2023-09-20T21:28:08Z")

</div>

> [@ty.frith](#):
>
> ```auto
> const axios = require('axios');
> 
> async function getManagementApiToken() {
> const data = {
> client_id: process.env.AUTH0_MANAGEMENT_API_CLIENT_ID,
> client_secret: process.env.AUTH0_MANAGEMENT_API_CLIENT_SECRET,
> audience: process.env.AUTH0_AUDIENCE,
> grant_type: 'client_credentials'
> };
> 
> try {
> const response = await axios.post(`https://${process.env.AUTH0_DOMAIN}/oauth/token`, data);
> return response.data.access_token;
> } catch (error) {
> console.error('Error getting Auth0 Management API Token:', error);
> throw error;
> }
> }
> 
> ```

Thanks - it’s working.

---

<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:** [September 20, 2023, 9:33pm UTC](https://community.auth0.com/t/problem-getting-access-token-from-oauth-token-end-point-payload/116672/7 "2023-09-20T21:33:17Z")

</div>

Awesome! Happy to help, thanks for following up!

---

<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:** [October 4, 2023, 9:33pm UTC](https://community.auth0.com/t/problem-getting-access-token-from-oauth-token-end-point-payload/116672/8 "2023-10-04T21:33:38Z")

</div>

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