# Automate Management API Tokens

**URL:** <https://community.auth0.com/t/automate-management-api-tokens/6310>\
**Category:** Get Help\
**Tags:** token-url, token, access-token, management-api\
**Created:** [April 21, 2017, 7:34am UTC](https://community.auth0.com/t/automate-management-api-tokens/6310 "2017-04-21T07:34:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jackyzhanchiu](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jackyzhanchiu/32/7117_2.png) [@jackyzhanchiu](https://community.auth0.com/u/jackyzhanchiu)\
**Post date:** [April 21, 2017, 7:34am UTC](https://community.auth0.com/t/automate-management-api-tokens/6310/1 "2017-04-21T07:34:15Z")

</div>

In the article here: [Management API Access Tokens - Auth0 Docs](https://auth0.com/docs/api/management/v2/tokens#automate-the-process) it describes the general steps of automating the process of generating a new API token for the management API. But there’s no shown example which leads to a lot of questions.

(I have a Node API running on Heroku):

- How will I automate this process? Do I get my backend to run a script (with the code provided in the link) at a 24-hour interval?
- Do I keep the API Token stored as an environment variable? Heroku is said to restart on change of environment variables

A full example would make this a lot more clear.

---

<div class="post-metadata">

**Author:** ![prashantT](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/prashantt/32/6002_2.png) [@prashantT](https://community.auth0.com/u/prashantT)\
**Post date:** [April 21, 2017, 12:17pm UTC](https://community.auth0.com/t/automate-management-api-tokens/6310/2 "2017-04-21T12:17:44Z")

</div>

You can keep the management api token in memory and check for it’s expiration before making call to Management API. Here is a simple example:

[https://github.com/ashishdasnurkar/apiv2token-sample](https://github.com/ashishdasnurkar/apiv2token-sample)

This demonstrates how this can be done in NodeJS. Similar concept can be applied to other language/frameworks. General idea is to keep the token in a in-memory cache with a timeout that matches the token expiration. If the token is not found then get a new one and add to the cache.

---

<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:** [March 2, 2018, 5:53am UTC](https://community.auth0.com/t/automate-management-api-tokens/6310/3 "2018-03-02T05:53:24Z")

</div>


