# How can I get external\_id from the user object?

**URL:** https://meta.discourse.org/t/how-can-i-get-external-id-from-the-user-object/147864
**Category:** Support
**Created:** [April 13, 2020, 7:46pm UTC](https://meta.discourse.org/t/how-can-i-get-external-id-from-the-user-object/147864 "2020-04-13T19:46:40Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![pnoeric](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pnoeric/32/177144_2.png) [@pnoeric](https://meta.discourse.org/u/pnoeric)
#### Post date: [April 13, 2020, 7:46pm UTC](https://meta.discourse.org/t/how-can-i-get-external-id-from-the-user-object/147864/1 "2020-04-13T19:46:40Z")

</div>

When I use the API to get the Discourse user object, it works fine, but I don’t see the external\_id included in there. If I have a Discourse user ID or username, how can I get the external\_id from that?

---

<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 13, 2020, 7:59pm UTC](https://meta.discourse.org/t/how-can-i-get-external-id-from-the-user-object/147864/2 "2020-04-13T19:59:57Z")

</div>

`http://localhost:3000/admin/users/1/blake.erickson.json`

Will have the SSO info:

 ![image](https://global.discourse-cdn.com/meta/original/3X/8/d/8d728744d487dd502be6de4082f1bd5d544a7f1e.png)

---

<div class="post-metadata">

### Author: ![pnoeric](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pnoeric/32/177144_2.png) [@pnoeric](https://meta.discourse.org/u/pnoeric)
#### Post date: [April 14, 2020, 6:37am UTC](https://meta.discourse.org/t/how-can-i-get-external-id-from-the-user-object/147864/3 "2020-04-14T06:37:28Z")

</div>

Aha - I was calling `/users/blake.erickson.json` (no `/admin`) which also returns a user object, but without `single_sign_on_record`.

Hey, why is it that the `/users/` endpoint will take (only?) a username, but if you want to get a user by their Discourse ID, then it’s `/admin/users/:id.json`? Just quirks of the API design?

Further weirdness: if I retrieve a user by their external\_id, calling `/users/by-external/:id.json`, then I don’t get the `single_sign_on_record`

So the API has some quirks… sometimes a user object has the `single_sign_on_record` properties, sometimes it doesn’t 😉

---

<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 14, 2020, 12:17pm UTC](https://meta.discourse.org/t/how-can-i-get-external-id-from-the-user-object/147864/4 "2020-04-14T12:17:07Z")

</div>

By design the admin endpoint will return more data than the non-admin endpoint. Yes, they are both fetching “user” records, but it would be super bad if the `/user/...` endpoint that regular users can call returned the same thing as `/admin/user/...`.

---

<div class="post-metadata">

### Author: ![pnoeric](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pnoeric/32/177144_2.png) [@pnoeric](https://meta.discourse.org/u/pnoeric)
#### Post date: [April 14, 2020, 12:21pm UTC](https://meta.discourse.org/t/how-can-i-get-external-id-from-the-user-object/147864/5 "2020-04-14T12:21:56Z")

</div>

Aha, I didn’t realize the `/user` endpoint would be available to individual users. I forgot that there is such a thing as User API keys.

I keep getting thrown by inconsistencies. Right now, if I want `single_sign_on_record`, I have to know the Discourse user ID (`/admin/users/:username.json` doesn’t work)… but most other API calls seem to require the username (like `/users/:username.json`).

And then there are separate API endoints that are _very similar_ and seem almost identical but return different results, i.e. `/admin/users` gives me `single_sign_on_record` data for the user, but calling just `/users/` does not.

None of this is a big deal, I’m figuring it out as I go… once I get further along, I might see if I can tweak the docs a bit and make some of this more clear.

---

<div class="post-metadata">

### Author: ![riking](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/riking/32/170938_2.png) [@riking](https://meta.discourse.org/u/riking)
#### Post date: [April 14, 2020, 7:00pm UTC](https://meta.discourse.org/t/how-can-i-get-external-id-from-the-user-object/147864/6 "2020-04-14T19:00:29Z")

</div>

The distinction here comes from the fact that the endpoints return the data needed to render the pages in the UI. Take a look here:

> [@Reverse engineer the Discourse API](https://meta.discourse.org/t/how-to-reverse-engineer-the-discourse-api/20576):
>
> Discourse is backed by a complete JSON api. Anything you can do on the site you can also do using the JSON api. The API is documented at [docs.discourse.org](https://docs.discourse.org). You can also use the [discourse\_api](https://github.com/discourse/discourse_api) Ruby gem as a client library. However, not every endpoint is documented. To determine how to do something with the JSON API here are some steps you can follow. Example: recategorize a topic. Go to a topic and start editing a category: Open Chrome dev tools, switch to the Network tab, select …

---

<div class="post-metadata">

### Author: ![pnoeric](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pnoeric/32/177144_2.png) [@pnoeric](https://meta.discourse.org/u/pnoeric)
#### Post date: [April 14, 2020, 7:02pm UTC](https://meta.discourse.org/t/how-can-i-get-external-id-from-the-user-object/147864/7 "2020-04-14T19:02:02Z")

</div>

Sure, I totally get it-- and I’ve been using that trick to monitor all those XHR requests. It’s all good. It’s just… inconsistent. 😉 But I am endlessly grateful that Discourse has such a strong API!

---

<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: [May 14, 2020, 7:02pm UTC](https://meta.discourse.org/t/how-can-i-get-external-id-from-the-user-object/147864/8 "2020-05-14T19:02:03Z")

</div>

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