mysterious-processor-51766
05/24/2023, 10:28 PMchilly-king-10285
05/24/2023, 10:28 PMchilly-king-10285
05/24/2023, 10:29 PMpatchIdentity endpoint uses JSON Patch to partially update an identity's field. The difference between "add" and "replace" operations in JSON Patch is as follows: - "add": This operation is used to add a new key-value pair to the target object or insert a new value into an array. If the target location already contains a value, the new value will overwrite the existing value. - "replace": This operation is used to replace an existing value at the target location with a new value. In the context of the patchIdentity endpoint, you would use "add" if you want to add a new field to the identity or insert a value into an array, and "replace" if you want to update the value of an existing field. Here's the relevant extract from the documentation: oprequired | string The operation to be performed. One of "add", "remove", "replace", "move", "copy", or "test". Source: [API Reference > kratos > reference > api > identity > Patch an Identity](https://www.ory.sh/docs/kratos/reference/api#tag/identity/operation/patchIdentity)mysterious-processor-51766
05/24/2023, 10:32 PM[
{
"op": "add",
"path": "/metadata_public",
"value": {"foo": "bar"}
}
]
and this does exactly the same thing:
[
{
"op": "replace",
"path": "/metadata_public",
"value": {"foo": "bar"}
}
]mysterious-processor-51766
05/24/2023, 10:33 PMchilly-king-10285
05/24/2023, 10:33 PMchilly-king-10285
05/24/2023, 10:34 PMuser_id in metadata_public when it already exists or create metadata_public with user_id when it doesn't exist, you can use the patchIdentity endpoint with the "add" operation. Here's an example of how to do this: 1. First, retrieve the identity using the GET /admin/identities/{id} endpoint to check if metadata_public exists or not. Source: [API Reference > kratos > reference > api > identity > Get an Identity](https://www.ory.sh/docs/kratos/reference/api#operation/getIdentity) 2. If metadata_public exists, use the "add" operation to add the user_id field to metadata_public. If metadata_public doesn't exist, use the "add" operation to create metadata_public with the user_id field. Here's an example JSON Patch request for adding or updating the user_id field in `metadata_public`: json [ { "op": "add", "path": "/metadata_public/user_id", "value": "your_user_id_value" } ] Send this JSON Patch request to the PATCH /admin/identities/{id} endpoint to update the identity. Source: [API Reference > kratos > reference > api > identity > Patch an Identity](https://www.ory.sh/docs/kratos/reference/api#operation/patchIdentity)mysterious-processor-51766
05/25/2023, 7:29 AMmetadata_public object when it does not exist 😄bland-eye-99092
05/25/2023, 7:46 AM