# API 500 on user creation if username is integer

**URL:** https://meta.discourse.org/t/api-500-on-user-creation-if-username-is-integer/222281
**Category:** Bug
**Tags:** rest-api
**Created:** [March 29, 2022, 8:15am UTC](https://meta.discourse.org/t/api-500-on-user-creation-if-username-is-integer/222281 "2022-03-29T08:15:32Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Seluj78](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/seluj78/32/254589_2.png) [@Seluj78](https://meta.discourse.org/u/Seluj78)
#### Post date: [March 29, 2022, 8:15am UTC](https://meta.discourse.org/t/api-500-on-user-creation-if-username-is-integer/222281/1 "2022-03-29T08:15:32Z")

</div>

Hi,

We’ve been having some trouble with the discourse API, and the responsible is the fact that the API sends a 500 when the `username` is an integer. If you cast that into a string it works…

I’ll fix this on my end and cast my usernames to string but can it be fixed or at least send a 400 back ?

---

<div class="post-metadata">

### Author: ![Seluj78](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/seluj78/32/254589_2.png) [@Seluj78](https://meta.discourse.org/u/Seluj78)
#### Post date: [March 29, 2022, 8:22am UTC](https://meta.discourse.org/t/api-500-on-user-creation-if-username-is-integer/222281/2 "2022-03-29T08:22:33Z")

</div>

Also, when something is incorrect you send a 200 back with `success: false` which is a bad design. Maybe change this ?

For example:

```plaintext
'{"success":false,"message":"Password est trop court (nombre minimal de caractères : 8)\\nPrimary email a déjà été pris","errors":{"password":["est trop court (nombre minimal de caractères : 8)"],"email":["a déjà été pris"]},"values":{"name":"Jules Lasne","username":"6666","email":"jules@datascientest.com"},"is_developer":false}'

```

This should return either a 400 for the password or a 409 for the email…

---

<div class="post-metadata">

### Author: ![blake](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/blake/32/157322_2.png) [@blake](https://meta.discourse.org/u/blake)
#### Post date: [April 4, 2022, 3:12pm UTC](https://meta.discourse.org/t/api-500-on-user-creation-if-username-is-integer/222281/3 "2022-04-04T15:12:21Z")

</div>

> [@Seluj78](#):
>
> but can it be fixed or at least send a 400 back

Yes, that can be fixed. Thanks for reporting this.

---

<div class="post-metadata">

### Author: ![blake](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/blake/32/157322_2.png) [@blake](https://meta.discourse.org/u/blake)
#### Post date: [April 4, 2022, 9:23pm UTC](https://meta.discourse.org/t/api-500-on-user-creation-if-username-is-integer/222281/5 "2022-04-04T21:23:01Z")

</div>

Alright fix is in:  
[https://github.com/discourse/discourse/commit/ec2930712dde7e7d380e62e0b73d0bd0c4e12c0a](https://github.com/discourse/discourse/commit/ec2930712dde7e7d380e62e0b73d0bd0c4e12c0a)

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [April 4, 2022, 11:42pm UTC](https://meta.discourse.org/t/api-500-on-user-creation-if-username-is-integer/222281/6 "2022-04-04T23:42:49Z")

</div>


