# Management API problems NodeExpress

**URL:** <https://community.auth0.com/t/management-api-problems-nodeexpress/79392>\
**Category:** Get Help\
**Tags:** management-api, auth0\
**Created:** [March 7, 2022, 12:50pm UTC](https://community.auth0.com/t/management-api-problems-nodeexpress/79392 "2022-03-07T12:50:22Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![nc14](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/nc14/32/33226_2.png) [@nc14](https://community.auth0.com/u/nc14)\
**Post date:** [March 7, 2022, 12:50pm UTC](https://community.auth0.com/t/management-api-problems-nodeexpress/79392/1 "2022-03-07T12:50:22Z")

</div>

Hi, I’m hoping someone can please help. I’m really stuck with how to set new metadata with the Management API in vanilla nodejs/express (no React/Angular etc).

I saw [this answer about getting a token](https://community.auth0.com/t/how-to-update-user-app-metadata/63193) but know there is also a way to automatically get tokens.

I’m particularly stuck with where this code is meant to go? My use case is very simple, I just want a user to be able to click a fill in a 1 field form and update their metadata with the result.

Where does that code go (from the example)? In app.js? In a controller? In the template?

If someone could just very simply (I’m a beginner!) explain this simple use case I know I will be fine doing more actions from there.

Right now I have an `app.js`, which uses a `router.js`, which forwards to a `userController`, which at the moment sends the user profile information to a Pug template at `localhost:3000/user` like this :

```auto
exports.user = (req, res) => {
    
    res.render('user', {
        user: req.oidc.user,
    });
};

```

Where it succesfully displays. If someone could explain very simple steps to use vanilla Express/NodeJS to simply add/read metadata from a user profile that would be amazing.

I have installed the Node auth0 library.

Thank you!!!

---

<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:** [March 7, 2022, 7:15pm UTC](https://community.auth0.com/t/management-api-problems-nodeexpress/79392/3 "2022-03-07T19:15:45Z")

</div>

Hi @nc14,

Thanks for reaching out to the Auth0 Community!

> [@nc14](#):
>
> I saw [this answer about getting a token](https://community.auth0.com/t/how-to-update-user-app-metadata/63193) but know there is also a way to automatically get tokens.
> 
> I’m particularly stuck with where this code is meant to go?

I understand that you are trying to use the Management API to update your user’s user\_metadata on your app.

To do so, you will need to first [get a Management API Token](https://auth0.com/docs/secure/tokens/access-tokens/get-management-api-access-tokens-for-production#get-access-tokens) using the **client\_credentials** grant, which will programmatically request for tokens.

Once you have the token, you can use it to make requests to the Management API [Update a user endpoint](https://auth0.com/docs/api/management/v2#!/Users/patch_users_by_id).

Lastly, you may find the [updateUserMetadata](https://auth0.github.io/node-auth0/ManagementClient.html#updateUserMetadata) reference useful.

Please let me know if you have any questions.

Thank you.

---

<div class="post-metadata">

**Author:** ![nc14](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/nc14/32/33226_2.png) [@nc14](https://community.auth0.com/u/nc14)\
**Post date:** [March 8, 2022, 5:49pm UTC](https://community.auth0.com/t/management-api-problems-nodeexpress/79392/5 "2022-03-08T17:49:03Z")

</div>

Hi thanks for this - I can now successfully get a token… can you please explain in more detail how I do this…

_Once you have the token, you can use it to make requests to the Management API [Update a user endpoint](https://auth0.com/docs/api/management/v2#!/Users/patch_users_by_id)._

---

<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:** [March 9, 2022, 12:24am UTC](https://community.auth0.com/t/management-api-problems-nodeexpress/79392/6 "2022-03-09T00:24:08Z")

</div>

Hi @nc14,

Thank you for your response.

You could use the ManagementClient to call the `updateUserMetadata` method to accomplish this in your Node Express App. See below.

```auto
var ManagementClient = require('auth0').ManagementClient;

var management = new ManagementClient({
  token: 'YOUR_API_V2_TOKEN',
  domain: 'YOUR_DOMAIN.auth0.com'
});

var params = { id: USER_ID };
var metadata = {
  address: '123th Node.js Street'
};

management.updateUserMetadata(params, metadata, function (err, user) {
  if (err) {
    // Handle error.
  }

  // Updated user.
  console.log(user);
});

```

Please let me know if there’s anything else I can do to help.

Thank you.

---

<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 24, 2022, 12:24am UTC](https://community.auth0.com/t/management-api-problems-nodeexpress/79392/7 "2022-03-24T00:24:39Z")

</div>

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