# Unable to make my token dynamic in my rule

**URL:** <https://community.auth0.com/t/unable-to-make-my-token-dynamic-in-my-rule/100693>\
**Category:** Get Help\
**Tags:** rules-management-api, management-api\
**Created:** [February 16, 2023, 11:02pm UTC](https://community.auth0.com/t/unable-to-make-my-token-dynamic-in-my-rule/100693 "2023-02-16T23:02:24Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![sandT](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@sandT](https://community.auth0.com/u/sandT)\
**Post date:** [February 16, 2023, 11:02pm UTC](https://community.auth0.com/t/unable-to-make-my-token-dynamic-in-my-rule/100693/1 "2023-02-16T23:02:24Z")

</div>

Hello, I created a machine to machine application which help me enable Auth0 management API. from that API a token was generated. Currently in my login rule, the token is hardcoded (copied and paste from the API explorer) but I would like it to be dynamic so the token can be read directly from the API explorer without me copying from there everyday (my token has a 24hrs expiration).  
Any idea on how to resolve it?

```auto
function (user, context, callback) {
  var ManagementClient = require('auth0').ManagementClient;
  var management = new ManagementClient({
    token: "eyJhb.......",
    domain: auth0.domain
  });

```

here is how I currently refer to my token and do not want to have to update it daily

---

<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 22, 2023, 2:03pm UTC](https://community.auth0.com/t/unable-to-make-my-token-dynamic-in-my-rule/100693/3 "2023-02-22T14:03:36Z")

</div>

Hi @sandT,

You can exchange client credentials for a fresh token. Do this by adding the client ID and secret as options in your management client instead of specifying the token directly.

There is an example on the first page of auth0-node docs: [ManagementClient - Documentation](https://auth0.github.io/node-auth0/ManagementClient.html).

---

<div class="post-metadata">

**Author:** ![sandT](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@sandT](https://community.auth0.com/u/sandT)\
**Post date:** [February 22, 2023, 6:21pm UTC](https://community.auth0.com/t/unable-to-make-my-token-dynamic-in-my-rule/100693/4 "2023-02-22T18:21:19Z")

</div>

Thanks Dan it worked!

---

<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 22, 2023, 7:11pm UTC](https://community.auth0.com/t/unable-to-make-my-token-dynamic-in-my-rule/100693/5 "2023-02-22T19:11:10Z")

</div>

No problem.

One thing I forgot to mention, keep in mind the [Management API rate limits](https://auth0.com/docs/troubleshoot/customer-support/operational-policies/rate-limit-policy/management-api-endpoint-rate-limits) when working with the API in a rule. You will quickly run into the limits if you are calling the managment API on every auth request.

---

<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 8, 2023, 7:11pm UTC](https://community.auth0.com/t/unable-to-make-my-token-dynamic-in-my-rule/100693/6 "2023-03-08T19:11:28Z")

</div>

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