# Account linking with Actions - \`getManagementApiToken\`

**URL:** <https://community.auth0.com/t/account-linking-with-actions-getmanagementapitoken/121543>\
**Category:** Get Help\
**Tags:** users, management-api\
**Created:** [November 23, 2023, 2:20pm UTC](https://community.auth0.com/t/account-linking-with-actions-getmanagementapitoken/121543 "2023-11-23T14:20:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tal1](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/tal1/32/52692_2.png) [@tal1](https://community.auth0.com/u/tal1)\
**Post date:** [November 23, 2023, 2:20pm UTC](https://community.auth0.com/t/account-linking-with-actions-getmanagementapitoken/121543/1 "2023-11-23T14:20:46Z")

</div>

Hey,  
I’ve seen this simple example of account linking through actions

> **[Link User Accounts](https://auth0.com/docs/manage-users/user-accounts/user-account-linking/link-user-accounts#account-linking-with-actions)**
>
> Understand how to link user accounts from various identity providers, so your users can authenticate from any account and be recognized by your app.

but I’m stuck with the `getManagementApiToken` function, that maybe I need to write on my own.  
Can someone provide any guidance for this function? how to use the `event` and `api` variables?

Moreover, what should be the value of `event.secrets.TENANT_DOMAIN`?

thanks

---

<div class="post-metadata">

**Author:** ![rueben.tiow](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rueben.tiow/32/11646_2.png) [@rueben.tiow](https://community.auth0.com/u/rueben.tiow)\
**Post date:** [November 28, 2023, 5:19pm UTC](https://community.auth0.com/t/account-linking-with-actions-getmanagementapitoken/121543/3 "2023-11-28T17:19:50Z")

</div>

Hi @tal1,

Welcome to the Auth0 Community!

It looks like the `getManagementApiToken` method is suppose to be a hardcoded value of your Management API token.

However, this is not ideal because the API token can expire and cause the code to fail in the future.

In this case, consider replacing the following code snippet:

```auto
  const token = await getManagementApiToken(event, api);
  const domain = event.secrets.TENANT_DOMAIN;
  const management = new ManagementClient({ domain, token });

```

with the following initialization of the `ManagementClient` class:

```auto
  const management = new ManagementClient({
      domain: event.secrets.domain,
      clientId: event.secrets.clientId,
      clientSecret: event.secrets.clientSecret,
  });

```

For managing secrets, you can configure them in the Action code editor. I recommend following the steps outlined in the [Write Your First Action - Add a secret](https://auth0.com/docs/customize/actions/write-your-first-action#add-a-secret) documentation.

If you have any questions, feel free to ask.

Thanks,  
Rueben

---

<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:** [December 12, 2023, 5:20pm UTC](https://community.auth0.com/t/account-linking-with-actions-getmanagementapitoken/121543/4 "2023-12-12T17:20:08Z")

</div>

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