User API question.

After creating a user with “Create a user” API, I deleted it with “Delete a user” API.

And when I try to create with the same ID with “Create a user” API, an error message appears saying “user_id violates unique constraint.”

Is the ID created once cannot be regenerated after deletion?

Hello, @crom08 Welcome to the Sendbird community!

Our servers need some time (not sure about the exact time) to delete the user from our database so you can’t do requests to create the user again after a few milliseconds you have deleted the user.

There is a database cache that the user might still be there even though the user was deleted from the actual database. If you would try now to create the user it should be fine.

Let me know if this helps.

Hello @Chinmaya_Gupta. I am facing the exact same issue. I deleted a user over 1 hour ago, and tried to create a new one but it’s still giving me a user_id constraint.
In my case, I am creating / deleting users based on their subscription status change on my website. If the user subscribes, a Sendbird account is created. If the user unsubscribes for example, the Sendbird account gets deleted. Since there is caching involved, am I better off deactivating/activating users instead of deleted/creating them on every subscription status change?

It seems that I was able to create the user again with the same ID after about 2 hours after I deleted it. To avoid this complication, I switched to activating/deactivating users instead. Hope this information helps.

Hello @ahamdan It may happen since this user is member of a group channel.

You should be okay to recreate if remove this user from group channel.

You can always deactivate a user (optionally remove it form all channels automatically)
A deactivated user is like a removed user.

Sendbird Docs

User | Chat Platform API | Sendbird Docs

Manage the attributes and functionalities of the users.

Set attribute is_active to false.

And leave_all_when_deactivated to true (optional)

Let me know if this helps.

1 Like