# How can I update users via API using the user id (not username)?

**URL:** https://meta.discourse.org/t/how-can-i-update-users-via-api-using-the-user-id-not-username/170203
**Category:** Development
**Tags:** rest-api
**Created:** [November 15, 2020, 5:06pm UTC](https://meta.discourse.org/t/how-can-i-update-users-via-api-using-the-user-id-not-username/170203 "2020-11-15T17:06:09Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![wilson29thid](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/wilson29thid/32/173700_2.png) [@wilson29thid](https://meta.discourse.org/u/wilson29thid)
#### Post date: [November 15, 2020, 5:06pm UTC](https://meta.discourse.org/t/how-can-i-update-users-via-api-using-the-user-id-not-username/170203/1 "2020-11-15T17:06:09Z")

</div>

I’d like my application to update my users’ linked discourse account: specifically the display name and groups the user is a member of (e.g. when they’re promoted in my application, they’re added to another forum group as well).

I expected to store a “discourse member id” reference in my application’s users table, and use that to make updates, e.g. `POST /users/{id}.json` with a payload like `{"name": "new name"}`. But it looks like all the API routes expect a `username` instead of an `id`.

I don’t understand why this would be the default: can’t users change their username? It seems like that would break the integration if they did.

How can I make changes like this reliably, using a consistent identifier (like `id`)?

---

<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: [November 16, 2020, 10:13pm UTC](https://meta.discourse.org/t/how-can-i-update-users-via-api-using-the-user-id-not-username/170203/2 "2020-11-16T22:13:01Z")

</div>

For now I think your best option is to make two api requests. One to [fetch the user by id](https://docs.discourse.org/#tag/Users/paths/~1admin~1users~1%7Bid%7D.json/get) in order to get the username, and the second request to update by username.

There is an option to update a user by `external_id` but I don’t think this can be used without single-sign-on enabled, but this way Discourse stores the id of the user of your application instead of the other way around.

---

<div class="post-metadata">

### Author: ![wilson29thid](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/wilson29thid/32/173700_2.png) [@wilson29thid](https://meta.discourse.org/u/wilson29thid)
#### Post date: [November 18, 2020, 6:41am UTC](https://meta.discourse.org/t/how-can-i-update-users-via-api-using-the-user-id-not-username/170203/3 "2020-11-18T06:41:55Z")

</div>

Thanks, I had a similar lightbulb moment after posting.

---

<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: [December 18, 2020, 6:46am UTC](https://meta.discourse.org/t/how-can-i-update-users-via-api-using-the-user-id-not-username/170203/4 "2020-12-18T06:46:23Z")

</div>

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