# כיצד ניתן לקשר לפרופיל משתמש לפי מזהה המשתמש שלו?

**URL:** https://meta.discourse.org/t/how-can-i-link-to-a-user-profile-by-their-user-id/183196
**Category:** Development
**Created:** [14 במרץ,‏ 2021,‏ 10:51am UTC](https://meta.discourse.org/t/how-can-i-link-to-a-user-profile-by-their-user-id/183196 "2021-03-14T10:51:42Z")
**Posts on this page:** 6
**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: [14 במרץ,‏ 2021,‏ 10:51am UTC](https://meta.discourse.org/t/how-can-i-link-to-a-user-profile-by-their-user-id/183196/1 "2021-03-14T10:51:42Z")

</div>

I have a members table in my application’s database, where I store application-specific information about a subset of members. One of the columns is `discourse_user_id`. I’d like to render a link to the member’s discourse profile. Is it possible to do that with just their user id?

I am not storing `discourse_user_name` because the user can change that, and then I’d have to worry about keeping them in sync.

The only way I can think of is to make an API request to `/admin/users/<user-id>.json` to get their username, but that would be a large number of requests to do on an index page, where I’m listing members with links to their profile.

The only other thing that comes to mind is to build a plugin to add a route, though that seems like a lot of effort for something that I’d expect I’m not the first person to ask about, so I wanted to check whether there’s another solution already?

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [15 במרץ,‏ 2021,‏ 4:23pm UTC](https://meta.discourse.org/t/how-can-i-link-to-a-user-profile-by-their-user-id/183196/2 "2021-03-15T16:23:24Z")

</div>

One idea is to put an external ID in the user record and then you could use `/by-external/:external_id`. The other is to use a webhook to notify your external database if they change their username. Another is to just disable changing usernames. From a quick look at `discourse/config/routes.db` I don’t see any route that uses the `user_id`.

---

<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: [16 במרץ,‏ 2021,‏ 6:53am UTC](https://meta.discourse.org/t/how-can-i-link-to-a-user-profile-by-their-user-id/183196/3 "2021-03-16T06:53:36Z")

</div>

Thanks @pfaffman, that’s very helpful. I think using an external id would be ideal, as it also solves another problem—[linking in the reverse direction](https://meta.discourse.org/t/link-custom-user-field-to-external-website/41218/53).

Poking around the API docs and a REST client, though, I don’t see how to update that field. Can I use that without enabling SSO? (And, even if I enabled SSO, would I be able to update it programmatically?)

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [16 במרץ,‏ 2021,‏ 1:18pm UTC](https://meta.discourse.org/t/how-can-i-link-to-a-user-profile-by-their-user-id/183196/4 "2021-03-16T13:18:58Z")

</div>

Sorry, I don’t know offhand. I’d have to poke in the source.

There is no reason to update the external key, keys aren’t supposed to change.

The other thing you might do is have both systems count on having the email address be the same.

My guess is that sso is what you’ll want to do

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [19 במרץ,‏ 2021,‏ 8:45pm UTC](https://meta.discourse.org/t/how-can-i-link-to-a-user-profile-by-their-user-id/183196/5 "2021-03-19T20:45:19Z")

</div>

You can try this:

```
https://SERVER/community/admin/users/list/active.json?filter=email%40hostname.com&show_emails=true

```

You’ll need to pass the API key in headers as documented elsehwere.

---

<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: [3 באפריל,‏ 2021,‏ 6:55pm UTC](https://meta.discourse.org/t/how-can-i-link-to-a-user-profile-by-their-user-id/183196/6 "2021-04-03T18:55:34Z")

</div>

I have created a plugin to enable this:

[https://github.com/29th/discourse-user-by-id](https://github.com/29th/discourse-user-by-id)

`/user-by-id/123/summary` redirects to `/u/janedoe/summary` etc.

I’m still surprised I had to do this, but at least it works!
