# 是否可以通过 Discourse API 根据 Discourse ID 获取用户？

**URL:** https://meta.discourse.org/t/is-it-possible-to-get-a-user-by-its-discourse-id-from-the-discourse-api/90014
**Category:** Support
**Created:** [2018年六月16日 11:14 UTC](https://meta.discourse.org/t/is-it-possible-to-get-a-user-by-its-discourse-id-from-the-discourse-api/90014 "2018-06-16T11:14:54Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Canapin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/canapin/32/119591_2.png) [@Canapin](https://meta.discourse.org/u/Canapin)
#### Post date: [2018年六月16日 11:14 UTC](https://meta.discourse.org/t/is-it-possible-to-get-a-user-by-its-discourse-id-from-the-discourse-api/90014/1 "2018-06-16T11:14:54Z")

</div>

Hi. I guess all is in the title.

---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [2018年七月6日 09:31 UTC](https://meta.discourse.org/t/is-it-possible-to-get-a-user-by-its-discourse-id-from-the-discourse-api/90014/2 "2018-07-06T09:31:23Z")

</div>

There is [https://meta.discourse.org/u/canapin.json](https://meta.discourse.org/u/canapin.json) but I don’t think there’s a route that uses the user id.

---

<div class="post-metadata">

### Author: ![Mittineague](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mittineague/32/114259_2.png) [@Mittineague](https://meta.discourse.org/u/Mittineague)
#### Post date: [2018年七月6日 22:07 UTC](https://meta.discourse.org/t/is-it-possible-to-get-a-user-by-its-discourse-id-from-the-discourse-api/90014/3 "2018-07-06T22:07:02Z")

</div>

> [@zogstrip](#):
>
> but I don’t think there’s a route that uses the user id.

There is only one route that works with an id and no username that I know of. (which seems odd to me because usernames can change whereas ids can’t.)

Anyway, it’s a staff-only route, eg.

```plaintext
https://meta.discourse.org/admin/users/174238.json

```

---

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [2018年七月6日 22:24 UTC](https://meta.discourse.org/t/is-it-possible-to-get-a-user-by-its-discourse-id-from-the-discourse-api/90014/4 "2018-07-06T22:24:45Z")

</div>

If you are using SSO, there is the `/users/by-external/{$user_id}.json` route.

---

<div class="post-metadata">

### Author: ![Canapin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/canapin/32/119591_2.png) [@Canapin](https://meta.discourse.org/u/Canapin)
#### Post date: [2018年七月6日 22:25 UTC](https://meta.discourse.org/t/is-it-possible-to-get-a-user-by-its-discourse-id-from-the-discourse-api/90014/5 "2018-07-06T22:25:20Z")

</div>

Is the discourse ID equal to the external ID?

---

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [2018年七月6日 22:27 UTC](https://meta.discourse.org/t/is-it-possible-to-get-a-user-by-its-discourse-id-from-the-discourse-api/90014/6 "2018-07-06T22:27:57Z")

</div>

> [@Canapin](#):
>
> Is the discourse ID equal to the external ID?

No, the external\_id is the id that is provided in the SSO payload from the SSO provider site. If you are using the [WP Discourse](https://github.com/discourse/wp-discourse) plugin, there is a function that you can use for this:

```plaintext
WPDiscourse\Utilities\Utilities::get_discourse_user($user_id)

```

`$user_id` in the function call is the WordPress user\_id.

---

<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: [2018年八月5日 22:28 UTC](https://meta.discourse.org/t/is-it-possible-to-get-a-user-by-its-discourse-id-from-the-discourse-api/90014/7 "2018-08-05T22:28:11Z")

</div>

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