# App\_metadata not merged but replaced

**URL:** <https://community.auth0.com/t/app-metadata-not-merged-but-replaced/67492>\
**Category:** Get Help\
**Tags:** auth0\
**Created:** [August 6, 2021, 12:00pm UTC](https://community.auth0.com/t/app-metadata-not-merged-but-replaced/67492 "2021-08-06T12:00:13Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![mihai.iordache](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/mihai.iordache/32/30694_2.png) [@mihai.iordache](https://community.auth0.com/u/mihai.iordache)\
**Post date:** [August 6, 2021, 12:00pm UTC](https://community.auth0.com/t/app-metadata-not-merged-but-replaced/67492/1 "2021-08-06T12:00:13Z")

</div>

The ‘Update a User’ ( /api/v2/users/{id} - Auth0 Management API) PATCH call has a different way of dealing with the metadata fields. These properties (user\_metadata and app\_metadata) “are merged instead of being replaced but be careful, the merge only occurs on the first level”.

So once the app\_metadata.userId is inserted it can only be changed but not removed, one may think.

But when testing the API with { “app\_metadata”: {} } the value is not merged but it is deleted resulting in no app\_metadata field.

---

<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:** [August 9, 2021, 9:35pm UTC](https://community.auth0.com/t/app-metadata-not-merged-but-replaced/67492/3 "2021-08-09T21:35:56Z")

</div>

Hi @mihai.iordache,

Welcome to the Auth0 Community!

To clarify, if a user had the following app\_metadata:

```auto
{
  "app_metadata": {
    "foo": "bar"
  }
}

```

And you sent a request with a body of:

```auto
{
  "app_metadata": {}
}

```

You would expect this as the result:

```auto
{
  "app_metadata": {
    "foo": "bar"
  }
}

```

Can you confirm this is what you are expecting? Also, in what scenario would you send an empty object like that? Why not omit it entirely?

---

<div class="post-metadata">

**Author:** ![mihai.iordache](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/mihai.iordache/32/30694_2.png) [@mihai.iordache](https://community.auth0.com/u/mihai.iordache)\
**Post date:** [August 10, 2021, 7:12am UTC](https://community.auth0.com/t/app-metadata-not-merged-but-replaced/67492/4 "2021-08-10T07:12:09Z")

</div>

Yes @dan.woda !  
The scenario that you describe it is exactly my understanding of the auth0 documentation in this case.  
But the code is doing something else. It is replacing not merging.

I’m asking about the empty object because we have a scenario that we are unable to understand. Some users are missing app\_metadata. We checked every where in our app and we are always sending app\_metadata with data in it. We also checked if we edit it somewhere without realising with an empty object. We do not.

So the bigger issue now is that we send the app\_metadata every time but in some cases it is not saved. Could this been and auth0 issue ?

---

<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:** [August 10, 2021, 3:50pm UTC](https://community.auth0.com/t/app-metadata-not-merged-but-replaced/67492/5 "2021-08-10T15:50:01Z")

</div>

It seems like an empty object is used to clear the user’s app metadata. I can understand how that could be confusing if you are expecting a merge.

> [@mihai.iordache](#):
>
> So the bigger issue now is that we send the app\_metadata every time but in some cases it is not saved. Could this been and auth0 issue ?

I’m not seeing any recent support cases, topics, or outages reporting anything related to this. It is unlikely that your tenant would be the only one affected by a bug in the management API.

---

<div class="post-metadata">

**Author:** ![mihai.iordache](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/mihai.iordache/32/30694_2.png) [@mihai.iordache](https://community.auth0.com/u/mihai.iordache)\
**Post date:** [August 11, 2021, 8:59am UTC](https://community.auth0.com/t/app-metadata-not-merged-but-replaced/67492/6 "2021-08-11T08:59:44Z")

</div>

Thank you very much for your help @dan.woda!  
This is very important for this project.

I have some further questions if you can help me with, please.

Is there a log where I can see in greater details if the user had app\_metadata on create, and if maybe there is another call that I am not aware of that is ‘deleting’ that part ?

I would like to know at what point the app\_metadata went missing.  
Is it at create ? Is it an update later ?

And I would like to know who is making those changes ?

---

<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:** [August 11, 2021, 7:11pm UTC](https://community.auth0.com/t/app-metadata-not-merged-but-replaced/67492/7 "2021-08-11T19:11:06Z")

</div>

> [@mihai.iordache](#):
>
> Is there a log where I can see in greater details if the user had app\_metadata on create, and if maybe there is another call that I am not aware of that is ‘deleting’ that part ?

There is a log of the request. If you go to your logs you should see the request and who/what app made it. For example:

```auto
{
  "date": "2021-08-11T19:05:55.349Z",
  "type": "sapi",
  "description": "Update a User",
  "client_id": "xxxxx",
  "client_name": "xxxxx",
  "details": {
    "request": {
      "method": "patch",
      "path": "/api/v2/users/xxxxx",
      "query": {},
      "body": {
        "app_metadata": {
          "foo": "bar"
        }
      },
      "channel": "https://manage.auth0.com/",
      "auth": {
        "user": {
          "user_id": "xxxxx",
          "name": "xxxxx",
          "email": "xxxxx"
         }
       }
//...etc...
}

```

You can also search the logs, which should help you narrow down the requests that are clearing the app metadata.

---

<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 13, 2021, 6:36pm UTC](https://community.auth0.com/t/app-metadata-not-merged-but-replaced/67492/8 "2021-10-13T18:36:26Z")

</div>

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