<@U04UQ68083H> Is it possible to define the userId...
# ory-copilot
q
@chilly-king-10285 Is it possible to define the userId when creating a user through the admin API?
b
A message from kapa.ai
Based on the knowledge sources provided, it's not possible to directly define a custom user ID when creating a user through the Ory admin API. When you create an identity using the admin API, Ory automatically generates a UUID for the identity. The admin API endpoint for creating identities is:
Copy code
POST /admin/identities
Looking at the API documentation and examples, you need to provide information like
schema_id
and
traits
(such as email or username), but there's no option to specify a custom ID. The system will automatically assign an ID to the newly created identity, which you can see in the response. For example, when creating a user, you would provide something like:
Copy code
json {   "schema_id": "<preset://email>",   "traits": {      "email": "<mailto:user@example.com|user@example.com>"   } }
And the response would include the system-generated ID:
Copy code
json {    "id":"auto-generated-uuid",    "credentials":{       "password":{          "type":"password",          "identifiers":[             "<mailto:user@example.com|user@example.com>"          ],          // ...       },       // ...    } }
If you need to associate your own identifier with Ory identities, you have a few options: 1. Store your custom ID in the identity's metadata fields (
metadata_admin
or
metadata_public
) 2. Use the Ory-generated ID in your application and maintain a mapping in your database 3. Store your custom ID as a trait in the identity schema [Invite users documentation](https://www.ory.sh/docs/kratos/manage-identities/invite-users) shows the typical flow for creating users through the admin API, and it always involves getting the auto-generated ID from the response.