<@U04UQ68083H> how can i migrate an identity to a ...
# ory-copilot
f
@chilly-king-10285 how can i migrate an identity to a new schema?
c
A message from kapa.ai
To migrate an identity to a new schema in Ory, you can follow these steps: 1. Save the existing identity using the
updateIdentity API
. You can do this with the following command:
Copy code
bash export IDENTITY_ID=$IDENTITY_ID   ory get identity "$IDENTITY_ID" --project "$PROJECT_ID" --format json-pretty > identity-"$IDENTITY_ID".json
2. Update the saved JSON to match the new identity schema. For example:
Copy code
bash -"schema_id" : "$OLD_SCHEMA_ID",   +"schema_id" : "$NEW_SCHEMA_ID",   "traits": {   -"foo": "foobar"   +"bar": barfoo   }
3. Update the identity using PUT:
Copy code
bash curl -d "@identity-$IDENTITY_ID.json" -X PUT https://$<http://ORY_SLUG.projects.oryapis.com/admin/identities/$IDENTITY_ID|ORY_SLUG.projects.oryapis.com/admin/identities/$IDENTITY_ID> \   -H "Authorization: Bearer $ORY_API_KEY" \   -H'Content-Type: application/json'
The
updateIdentity API
overwrites the existing identity with the one provided in the request body. Omit any fields that should not be changed, including the
credentials
field. This should return the modified identity as the response. If you have more identities to be patched to the new schema, repeat the above process for each of them. For more details, you can refer to the [Ory documentation](https://www.ory.sh/docs/identities/model/manage-identity-schema#update-identities-to-use-a-new-schema).