# Controleren op unieke gebruikersnaam via API?

**URL:** https://meta.discourse.org/t/checking-for-unique-username-via-api/306504
**Category:** SSO
**Tags:** rest-api
**Created:** [2 mei 2024 om 18:07 UTC](https://meta.discourse.org/t/checking-for-unique-username-via-api/306504 "2024-05-02T18:07:17Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Earnie\_Baird](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/earnie_baird/32/380079_2.png) [@Earnie\_Baird](https://meta.discourse.org/u/Earnie_Baird)
#### Post date: [2 mei 2024 om 18:07 UTC](https://meta.discourse.org/t/checking-for-unique-username-via-api/306504/1 "2024-05-02T18:07:17Z")

</div>

We are using Discourse with SSO and are creating users via the API.

There is concern that if we leverage the email address for the username it will be easy to guess personal emails at gmail so we’d like to just create unique usernames by using First Name + a Number (eg Bill1, Bill2, Bill3) and users can always change them.

Is there a way to check if a username is unique via the API? The thought is that we can keep looping until we find a username that is unique.

Also would be interested to hear if anyone has any other ideas for an alternate approach. One thought was doing something like First Name + Last Initial + 4 Random numbers or similar.

Thanks

---

<div class="post-metadata">

### Author: ![supermathie](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/supermathie/32/507518_2.png) [@supermathie](https://meta.discourse.org/u/supermathie)
#### Post date: [2 mei 2024 om 19:01 UTC](https://meta.discourse.org/t/checking-for-unique-username-via-api/306504/2 "2024-05-02T19:01:07Z")

</div>

> We are using Discourse with SSO and are creating users via the API.

Clarification: Are you using [Discourse Connect](https://meta.discourse.org/t/13045?silent=true) or creating the users by hand?

It kind of sounds like you’re doing more work than you need to.

Using [Discourse Connect](https://meta.discourse.org/t/13045?silent=true) is probably easier and then you can let Discourse itself find a unique username that’s close to what you suggest.

---

<div class="post-metadata">

### Author: ![Earnie\_Baird](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/earnie_baird/32/380079_2.png) [@Earnie\_Baird](https://meta.discourse.org/u/Earnie_Baird)
#### Post date: [2 mei 2024 om 20:23 UTC](https://meta.discourse.org/t/checking-for-unique-username-via-api/306504/3 "2024-05-02T20:23:23Z")

</div>

Thanks for your response @supermathie . We are using [Discourse connect](https://meta.discourse.org/t/13045?silent=true) and as it turns out whenI send Bill two times the second Bill is created as Bill1 so it looks like I’m good. Appreciate your help!

---

<div class="post-metadata">

### Author: ![supermathie](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/supermathie/32/507518_2.png) [@supermathie](https://meta.discourse.org/u/supermathie)
#### Post date: [2 mei 2024 om 21:48 UTC](https://meta.discourse.org/t/checking-for-unique-username-via-api/306504/4 "2024-05-02T21:48:01Z")

</div>

> [@Earnie\_Baird](#):
>
> when I send Bill two times the second Bill is created as Bill1

Exactly! The most important thing is keeping your external ID unique for the user. pass in a “sensible” username and let Discourse do the work.

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [1 juni 2024 om 21:48 UTC](https://meta.discourse.org/t/checking-for-unique-username-via-api/306504/5 "2024-06-01T21:48:42Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
