How does one change a username via the API?

סיכום מבוסס בינה מלאכותית

In a discussion about changing a username via the API, jezra reported that a PUT request to /users/MYUSER with a JSON payload didn’t update the username despite returning a 200 status. blake provided a working alternative using the endpoint /u/USERNAME/preferences/username.json with form-data parameters, successfully changing the username to “blake2”. jezra confirmed this solution worked. Separately, hellekin questioned whether changing the “system” username is safe. Referencing prior threads, hellekin noted conflicting opinions: while codinghorror warned against changing the system username (as it serves as a unique identifier), niemeyer indicated it is technically configurable by admins, though uncertainty remains about whether internal code still relies on the original username. The thread concludes with the confirmed working API method for regular users, but leaves the safety of renaming the system user unresolved.

While using the API and making a put request to:
MYDISCOURSE/users/MYUSER?api_key=MYSYSTEMAPIKEY&api_username=system
with a json payload of:
{“username”:“helloworld”}
I am receiving a response with a code of 200 and a body that indicates the username has not been changed.

Try this endpoint instead:

curl -i -sS -X PUT "http://127.0.0.1:3000/u/blake/preferences/username.json"  \
-H "Content-Type: multipart/form-data;" \
-F "api_key=a66d01fbe98cc51b2747d8bfe99f81d7adca18317fbf3c43aa20f340d8e25bfe"  \
-F "api_username=system" \
-F "new_username=blake2"

And it will output:

{"id":1,"username":"blake2"}

I was wondering: is it safe to change the system username?

Looks like this is not confirmed yet.

Thank you @blake that was exactly what I needed. :slight_smile: