<@U04UQ68083H> How do I create an identity for an ...
# ory-copilot
c
@chilly-king-10285 How do I create an identity for an email, or get an identity that already exists for that email?
b
A message from kapa.ai
To create an identity for an email in Ory, you use the Create Identity API. Here’s an example using a cURL command:
Copy code
bash curl --request POST -sL \   --header "Authorization: Bearer <your-ory-api-key>" \   --header "Content-Type: application/json" \   --data '{     "schema_id": "<preset://email>",     "traits": {       "email": "<mailto:user@example.org|user@example.org>"     }   }' https://<your-project-slug>.<http://projects.oryapis.com/admin/identities|projects.oryapis.com/admin/identities>
This will create a new identity with the specified email, provided that the email does not already exist as an identifier in your system. If the email already exists, you will receive an error message like:
Copy code
{
  "id": 4000007,
  "text": "An account with the same identifier (email, phone, username, ...) exists already.",
  "type": "error"
}
[Create identities](https://www.ory.sh/docs/kratos/manage-identities/create-users-identities) | [UI error message](https://www.ory.sh/docs/kratos/concepts/ui-messages#an-account-with-the-same-identifier-email-phone-username--exists-already-4000007) To get an identity that already exists for a given email, you must first know the identity’s ID, as the Ory API does not provide a direct “get by email” endpoint. Typically, you would: 1. Store the mapping between email and identity ID in your application when you create the identity. 2. Use the Get Identity API to retrieve the identity by its ID. Example (Go SDK):
Copy code
go getIdentity, r, err := apiClient.IdentityApi.GetIdentity(oryAuthedContext, identityId).Execute()
[Go SDK example](https://www.ory.sh/docs/kratos/sdk/go#identity-api) If you do not have the identity ID, you cannot directly query by email using the public Ory APIs according to the available documentation. Summary: - To create: Use the Create Identity API with the email as a trait. - To get: You need the identity ID; there is no direct “get by email” API in the documented endpoints. If you need to support “get or create” by email, you must implement this logic in your application: first search for the identity (by maintaining your own mapping), and if not found, create it.