Upsert app_metadata with the User Import API and Merging app_metadata

Problem statement

The user update Management API endpoint merges the existing top-level attributes of app metadata. E.g., if app1 exists, updating the user for app2 generates an app_metadata like the following;

app_metadata: {
"app1": { "key1": "value1", "key2": "value2" },
"app2": { "key3": "value3", "key4": "value4" }
}

Does the Upsert option of the user import management API merge the app_metadata at the top-level attributes similar to this API?

Solution

The user import Management API allows “upserting” the app_metadata field. However, the operation does not preserve the existing keys, which unfortunately means that the import API overwrites the app metadata with what is available in the import file.

If the existing app metadata of the users has to be preserved, exporting the users and merging them with the import file is required before running the import.