Hey everyone! I am trying to push data into a new array under all of my users so when they order an item my api gets the users metadata then pushes that order to the array under their profile. However, when i tried using the patch request it only replaced the item instead of creating an array. Is there something specific I can do when it comes to calling the management API to push data into an array?
Welcome to the Auth0 Community!
As explained in this doc,
The metadata fields are an exception to this rule (
user_metadataand
app_metadata). These properties are merged instead of being replaced but be careful, the merge only occurs on the first level.
For your use case, you want to append an item to an array under an attribute in the user_metadata, this is not adding a new attribute under the user_metadata, therefore, the value saved in the attribute got replaced instead of merged.
To add a new item to the array object, let’s say adding "2"
to "arr": ["1"]
under user_metadata, please use this:
{
"user_metadata":{
"arr": ["1","2"]
}
}
Hope this helps!