narrow-hospital-35452
01/07/2025, 8:49 AMv1
and v2
I want to change the data of schema v1
and update the traits also
how to do that?brief-egg-61061
01/07/2025, 8:49 AMbrief-egg-61061
01/07/2025, 8:50 AMv1
, you'll need to follow these steps: 1. Create a new schema (let's call it v2
) with the desired changes. 2. Update the identities to use the new schema. 3. Modify the traits of the updated identities. Here's how you can do this: 1. First, create your new schema v2
using the Ory Console or CLI. Make sure it includes all the necessary fields, including any new ones you want to add. 2. To update the identities from v1
to v2
, you'll need to use the Admin API. Here's an example using cURL: bash curl --location --request PATCH "https://$<http://ORY_SLUG.projects.oryapis.com/admin/identities/$IDENTITY_ID|ORY_SLUG.projects.oryapis.com/admin/identities/$IDENTITY_ID>" \ --header "Authorization: Bearer $ORY_API_KEY" \ --header "Content-Type: application/json" \ --data-raw '[ { "op": "replace", "path": "/schema_id", "value": "v2" }, { "op": "add", "path": "/traits/new_field", "value": "new_value" } ]'
Replace $IDENTITY_ID
, $ORY_SLUG
, and $ORY_API_KEY
with your actual values. This example updates the schema to v2
and adds a new trait called new_field
. 3. To update the traits, you can include the changes in the same PATCH request as shown above. Add, remove, or modify traits as needed. Remember that you'll need to do this for each identity that you want to update from v1
to v2
. It's important to note that updating identity schemas can be a sensitive operation. Always backup your data before making such changes, and test the process thoroughly in a non-production environment first. For more detailed information on managing identity schemas and updating identities, you can refer to the following Ory documentation: [Manage identity schemas](https://www.ory.sh/docs/identities/model/manage-identity-schema) [Update identities to use a new schema](https://www.ory.sh/docs/identities/model/manage-identity-schema#update-identities-to-use-a-new-schema) These resources provide comprehensive guidance on the process and best practices for updating identity schemas and traits.narrow-hospital-35452
01/13/2025, 4:44 AMbrief-egg-61061
01/13/2025, 4:44 AMbrief-egg-61061
01/13/2025, 4:44 AMmetadata_public
field of an identity along with updating the schema and traits. This can be done using the same PATCH request to the Admin API. Here's how you can modify the previous example to include updating the `metadata_public`: bash curl --location --request PATCH "https://$<http://ORY_SLUG.projects.oryapis.com/admin/identities/$IDENTITY_ID|ORY_SLUG.projects.oryapis.com/admin/identities/$IDENTITY_ID>" \ --header "Authorization: Bearer $ORY_API_KEY" \ --header "Content-Type: application/json" \ --data-raw '[ { "op": "replace", "path": "/schema_id", "value": "v2" }, { "op": "add", "path": "/traits/new_field", "value": "new_value" }, { "op": "replace", "path": "/metadata_public", "value": { "new_public_field": "public_value", "existing_field": "updated_value" } } ]'
In this example, we've added a new operation to update the metadata_public
. This will replace the entire metadata_public
object with the new values provided. A few important points to note: 1. The metadata_public
field is visible to the identity owner and can be accessed through user-facing APIs. 2. When using the "replace" operation for metadata_public
, it will overwrite the entire existing metadata_public
object. Make sure to include any existing fields you want to keep. 3. If you want to update only specific fields within metadata_public
without replacing the entire object, you can use separate "add" or "replace" operations for individual fields. For more detailed information on managing identity metadata, you can refer to the Ory documentation: [Identity metadata & traits](https://www.ory.sh/docs/kratos/manage-identities/managing-users-identities-metadata) This resource provides comprehensive guidance on working with identity metadata, including the differences between metadata_public
and metadata_admin
, and how to manage them effectively.narrow-hospital-35452
01/13/2025, 6:02 AMbrief-egg-61061
01/13/2025, 6:02 AMbrief-egg-61061
01/13/2025, 6:03 AMjson { "type": "object", "properties": { "traits": { "type": "object", "properties": { "phone": { "type": "string", "format": "tel", "title": "Phone number", "<http://ory.sh/kratos|ory.sh/kratos>": { "verification": { "via": "sms" } } } } } } }
Notice that the "phone" field is not listed in the "required" array of the schema. This makes it optional. 3. If you want to remove the phone number entirely, you can use the "remove" operation in your PATCH request: json { "op": "remove", "path": "/traits/phone" }
Remember to update your schema first if necessary, then update the identity. For more information on customizing identity schemas and handling phone numbers, you can refer to these Ory documentation pages: [Phone number and password](https://www.ory.sh/docs/kratos/manage-identities/customize-identity-schema#phone-number-and-password) [Phone number verification](https://www.ory.sh/docs/kratos/self-service/flows/verify-email-account-activation#phone-number-verification) These resources provide examples and best practices for working with phone numbers in Ory identity schemas. If you continue to face issues after trying these solutions, please provide more details about your current schema and the exact PATCH request you're making, so I can offer more specific guidance.