boundless-artist-2317
06/25/2024, 10:36 AMchilly-king-10285
06/25/2024, 10:36 AMchilly-king-10285
06/25/2024, 10:37 AMPOST /admin/identities endpoint to create an identity. The request body should include the schema_id and traits for the identity. Here is an example of how to use this endpoint with `curl`: bash curl --request POST -sL \ --header "Authorization: Bearer ory_pat_xRKLsFEOUFQFVBjd6o3FQDifaLYhabGd" \ --header "Content-Type: application/json" \ --data '{ "schema_id": "<preset://email>", "traits": { "email": "[[email protected]]" } }' <https://playground.projects.oryapis.com/admin/identities> The server response will contain the created identity. Note that this command does not create a password or any other type of credential for the identity. You can change the schema_id to reflect the schema you want to use for this identity. Similarly, the trait key/values depend on your schema as well ([source](https://www.ory.sh/docs/kratos/manage-identities/create-users-identities)). Using the Ory SDK: If you are using the Ory SDK, you can use the CreateIdentity method to create an identity. Here is an example of how to use this method in Go: go package main import ( "context" "fmt" "os" ory "<http://github.com/ory/kratos-client-go|github.com/ory/kratos-client-go>" ) func main() { configuration := ory.NewConfiguration() configuration.Servers = []ory.ServerConfiguration{ { URL: "<http://127.0.0.1:4434>", // Kratos Admin API }, } apiClient := ory.NewAPIClient(configuration) CreateIdentityBody := *ory.NewCreateIdentityBody( "default", map[string]interface{}{ "email": "[[email protected]", "name": map[string]string{ "first": "foo", "last": "bar", }, }, ) // CreateIdentityBody | (optional) createdIdentity, r, err := apiClient.IdentityApi.CreateIdentity(context.Background()).CreateIdentityBody(CreateIdentityBody).Execute() if err != nil { fmt.Fprintf(os.Stderr, "Error when calling `FrontendApi.CreateIdentity``: %v\n", err) fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) } // response from `CreateIdentity`: Identity fmt.Fprintf(os.Stdout, "Created identity with ID: %v\n", createdIdentity.Id) } This code creates an identity with the default schema and sets the email and name traits ([source](https://www.ory.sh/docs/kratos/self-hosted/go#createidentity-and-deleteidentity)). Remember that creating an identity does not automatically create credentials for that identity. You can import credentials such as passwords, social sign in configurations, or multifactor methods using the same POST /admin/identities endpoint or the CreateIdentity method ([source](https://www.ory.sh/docs/reference/api)).