# Update app\_metadata using Management API

**URL:** <https://community.auth0.com/t/update-app-metadata-using-management-api/116624>\
**Category:** Get Help\
**Tags:** users, management-api\
**Created:** [September 19, 2023, 3:14pm UTC](https://community.auth0.com/t/update-app-metadata-using-management-api/116624 "2023-09-19T15:14:07Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dpatel](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@dpatel](https://community.auth0.com/u/dpatel)\
**Post date:** [September 19, 2023, 3:14pm UTC](https://community.auth0.com/t/update-app-metadata-using-management-api/116624/1 "2023-09-19T15:14:08Z")

</div>

Hi all,

I’m attempting to update app\_metadata using the Management API. I’m new to Auth0 and I’m not sure why I’m receiving a 400 error when attempting to send this request. Here is my code:

```auto
const patchUserOrg = async (accessToken, org, user) => {
  const id = user.sub.split('|')[1];

  const config = {
    method: 'PATCH',
    url: `https://${domain}/api/v2/users/${id}`,
    headers: {
      authorization: `Bearer ${accessToken}`,
      'content-type': 'application/json',
    },
    data: {
      app_metadata: {
        active: `${org}`,
      },
    },
  };

  const res = await axios(config);
  return res.data;
};

```

I’m receiving the access token through the Auth0 dashboard (i.e. Applications \> APIs \> Auth0 Management API \> API Explorer). I understand this is not the proper way to get it but I’m doing this purely for testing to ensure the request works and performs the intended action. I’m receiving the user\_id by parsing the sub property in the user object provided by the Auth0 hook. For the ‘domain’, I’m using the URL listed underneath General Settings \> Identifier (on the same Auth0 Management API page).

What I’m trying to do? I’m trying to utilize the ‘active’ property on the app\_metadata section to manage which profile my web application should show (i.e. if its set to org1, my backend API calls will fetch all the org1 specific data; if its set to org2, my backend API calls will fetch all the org2 specific data). If anyone knows a better and more simplistic way to implement this functionality, I’m definitely open to suggestions.

Thank you for taking the time to read this.

Best,  
dhpcc

---

<div class="post-metadata">

**Author:** ![gparascandolo](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/gparascandolo/32/38788_2.png) [@gparascandolo](https://community.auth0.com/u/gparascandolo)\
**Post date:** [September 19, 2023, 7:23pm UTC](https://community.auth0.com/t/update-app-metadata-using-management-api/116624/3 "2023-09-19T19:23:14Z")

</div>

Hey @dpatel 👋

You need to pass the whole Auth0 user\_id to the Management API endpoint, don’t split the `user.sub` value for the API request - this is causing the 400 Bad Request response.

Try it it again with simply `const id = user.sub;`

You can also test the API call here after setting the setting the API Token: [Auth0 Management API v2](https://auth0.com/docs/api/management/v2/users/patch-users-by-id)

Hope this helps!

---

<div class="post-metadata">

**Author:** ![dpatel](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@dpatel](https://community.auth0.com/u/dpatel)\
**Post date:** [September 20, 2023, 1:09pm UTC](https://community.auth0.com/t/update-app-metadata-using-management-api/116624/4 "2023-09-20T13:09:27Z")

</div>

Thank you so much for your help. This solved my issue.

---

<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:** [October 4, 2023, 1:09pm UTC](https://community.auth0.com/t/update-app-metadata-using-management-api/116624/5 "2023-10-04T13:09:39Z")

</div>

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