# Refresh API Management Token on NodeJS

**URL:** <https://community.auth0.com/t/refresh-api-management-token-on-nodejs/38157>\
**Category:** Get Help\
**Tags:** token, management-api, auth0\
**Created:** [February 19, 2020, 8:57pm UTC](https://community.auth0.com/t/refresh-api-management-token-on-nodejs/38157 "2020-02-19T20:57:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![hugo.delacruz](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/hugo.delacruz/32/14067_2.png) [@hugo.delacruz](https://community.auth0.com/u/hugo.delacruz)\
**Post date:** [February 19, 2020, 8:57pm UTC](https://community.auth0.com/t/refresh-api-management-token-on-nodejs/38157/1 "2020-02-19T20:57:55Z")

</div>

Hello guys, I am looking for a way to programmatically refresh/renew my token on the backend. I have the following situation:  
When a user is created on the backend of my platform, I call the API Management of Auth0 to create the user as well on my Auth0 account. So far, I was using an API Management Token that I copied and pasted from my app, directly from the Auth0 dashboard, but it expires after maximum 30 days. So I need a way to renew it.  
I followed this tutorial [Get Management API Access Tokens for Production - Auth0 Docs](https://auth0.com/docs/api/management/v2/get-access-tokens-for-production) but what I get seems to be more like an access token (rather than an API Management token, which is longer), and if I try to authenticate against the /api/v2/users I get a “wrong token” error.

This is my code so far:

> const options = {  
> method: ‘POST’,  
> url: `https://${process.env.AUTH0_DOMAIN}/oauth/token`,  
> headers: { ‘content-type’: ‘application/x-www-form-urlencoded’ },  
> form: {  
> grant\_type: ‘client\_credentials’,  
> client\_id: process.env.AUTH0\_CLIENT\_ID,  
> client\_secret: process.env.AUTH0\_CLIENT\_SECRET,  
> audience: `https://${process.env.AUTH0_DOMAIN}/api/v2/`,  
> },  
> };  
> let newToken;  
> await request(options, (error, response, body) =\> {  
> if (error) throw new Error(error);
> 
> console.log(‘\*\*\*\*\*\*\*\*\*\*’);  
> newToken = JSON.parse(body).access\_token;  
> console.log(newToken); // Prints what seems to be an access token  
> });

Then, when I try to use it:

> const auth0CallOptions = {  
> url: ‘https://MY\_DOMAIN/api/v2/users’,  
> method: ‘POST’,  
> auth: {  
> bearer: newToken,  
> },  
> form: {  
> email: Email,  
> user\_metadata: {  
> phone\_number: Phone,  
> username: UserName,  
> }, …

It prints an error **“Invalid token”**. I made sure about sending the token that I got on the first call, even by copying and pasting it.

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [February 20, 2020, 8:12pm UTC](https://community.auth0.com/t/refresh-api-management-token-on-nodejs/38157/3 "2020-02-20T20:12:27Z")

</div>

Hi @hugo.delacruz,

There is pre-built code to request a management API token if you navigate to your Auth0 Dashboard \> APIs \> Auth0 Management API \> Test \> Node.js.

Let me know if this works for you.

Thanks,  
Dan

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [March 6, 2020, 12:12am UTC](https://community.auth0.com/t/refresh-api-management-token-on-nodejs/38157/4 "2020-03-06T00:12:33Z")

</div>

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