Skip to main content

identity_already_exists

An identity with this external ID already exists in your Unkey workspace. Use the existing identity or choose a different unique external ID.
2 min read
Danger
err:unkey:data:identity_already_exists
Example

What Happened?#

This error occurs when you're trying to create an identity with an external ID that already exists in your Unkey workspace. External IDs must be unique within a workspace to avoid confusion and maintain data integrity.

Common scenarios that trigger this error:

  • Creating an identity with an external ID that's already in use
  • Re-creating a previously deleted identity with the same external ID
  • Migration or import processes that don't check for existing identities
  • Duplicate API calls due to retries or network issues

Here's an example of a request that would trigger this error:

How To Fix#

When you encounter this error, you have several options:

  1. Use a different external ID: If creating a new identity, use a unique external ID
  2. Update the existing identity: If you want to modify an existing identity, use the update endpoint instead
  3. Get the existing identity: If you just need the identity information, retrieve it rather than creating it
  4. Implement upsert logic: Use a get-or-create pattern in your code

Here's how to update an existing identity:

Or implement a get-or-create pattern in your code:

Common Mistakes#

  • Not checking for existing identities: Failing to check if an identity already exists before creating it
  • Retry loops: Repeatedly trying to create the same identity after a failure
  • Case sensitivity: Not accounting for case sensitivity in external IDs
  • Cross-environment duplication: Using the same external IDs across development and production environments