# Unable to GET user by External ID

**URL:** https://meta.discourse.org/t/unable-to-get-user-by-external-id/154996
**Category:** Development
**Tags:** rest-api
**Created:** [June 16, 2020, 1:45pm UTC](https://meta.discourse.org/t/unable-to-get-user-by-external-id/154996 "2020-06-16T13:45:35Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![mpemburn](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mpemburn/32/178585_2.png) [@mpemburn](https://meta.discourse.org/u/mpemburn)
#### Post date: [June 16, 2020, 1:45pm UTC](https://meta.discourse.org/t/unable-to-get-user-by-external-id/154996/1 "2020-06-16T13:45:35Z")

</div>

Hi,

I’ve been attempting to get a user by external ID using the docs:

`https://docs.discourse.org/#tag/Users/paths/~1u~1by-external~1{external_id}.json/get`

It returns a “404 not found” with any user I try. Using the same URI and API key and username, I can get categories and groups . Any suggestions?

Regards,

Mark Pemburn  
Blue Ocean Ideas

---

<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: [June 16, 2020, 2:21pm UTC](https://meta.discourse.org/t/unable-to-get-user-by-external-id/154996/2 "2020-06-16T14:21:19Z")

</div>

See [How to reverse engineer the Discourse API](https://meta.discourse.org/t/how-to-reverse-engineer-the-discourse-api/20576)

---

<div class="post-metadata">

### Author: ![RGJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rgj/32/523185_2.png) [@RGJ](https://meta.discourse.org/u/RGJ)
#### Post date: [June 16, 2020, 4:31pm UTC](https://meta.discourse.org/t/unable-to-get-user-by-external-id/154996/3 "2020-06-16T16:31:48Z")

</div>

@pfaffman I do not understand your response, it does not contain an answer. That topic shows how to find out about endpoints that are not documented. This one is, and it is one of the very few API calls that cannot be reverse engineered like that, since this specific API endpoint is never called by the Ember frontend ?

@mpemburn it should work, the documentation looks correct. The external ID is the ID in your remote database, which is passed when you have SSO enabled. Can you share your code?

---

<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: [June 16, 2020, 4:35pm UTC](https://meta.discourse.org/t/unable-to-get-user-by-external-id/154996/4 "2020-06-16T16:35:52Z")

</div>

> [@RGJ](#):
>
> This one is, and it is one of the very few API calls that cannot be reverse engineered like that

Oops. Most often the answer to "the API documentation is broken, how do I . . . " is what I linked to. Looking more carefully it’s painfully apparent that something involving external IDs can’t be accessed via the UX. Lucky for Mark that you’re paying closer attention!

---

<div class="post-metadata">

### Author: ![RGJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rgj/32/523185_2.png) [@RGJ](https://meta.discourse.org/u/RGJ)
#### Post date: [June 16, 2020, 5:38pm UTC](https://meta.discourse.org/t/unable-to-get-user-by-external-id/154996/6 "2020-06-16T17:38:06Z")

</div>

~~Theory #1:~~  
~~Most of the time (not always) the external ID is a database ID and thus a numeric value. Are you sure your external ID is `mark89` ? Does `SingleSignOnRecord.find_by(external_id: 'mark89')` return a database record?~~

~~Theory #2:~~  
~~Your staging site does not have SSO enabled, which usually goes hand in hand with external ID’s. Are you sure external ID’s are present ?~~

Wait… Your headers are in a cookie? That’s not ok… it should be like this:

```plaintext
curl --location --request GET 'https://discourse.example.com/u/by-external/mark89.json'
    --header 'Accept: application/json' 
    --header 'Api-Key=[Api-Key]'
    --header 'Api-Username=system'

```

---

<div class="post-metadata">

### Author: ![mpemburn](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mpemburn/32/178585_2.png) [@mpemburn](https://meta.discourse.org/u/mpemburn)
#### Post date: [June 17, 2020, 3:09pm UTC](https://meta.discourse.org/t/unable-to-get-user-by-external-id/154996/7 "2020-06-17T15:09:21Z")

</div>

Ah, alas, that doesn’t work either.

I have tried this same request using the Wordpress Discourse plugin and it doesn’t work with that either, though request to get a user by email does. Thinking that it might be a problem with our sandbox version of Discourse (which is what I’ve been testing with up to this point), I tried it on our production instance, and the story is the same. Not sure what to do from here, but I really need this to work.

Mark

---

<div class="post-metadata">

### Author: ![RGJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rgj/32/523185_2.png) [@RGJ](https://meta.discourse.org/u/RGJ)
#### Post date: [June 17, 2020, 4:33pm UTC](https://meta.discourse.org/t/unable-to-get-user-by-external-id/154996/9 "2020-06-17T16:33:01Z")

</div>

> [@mpemburn](#):
>
> Ah, alas, that doesn’t work either.

Did you check my two theories that I wrote before I saw that you were sending the auth headers in the wrong way?

Theory #1:  
Most of the time (not always) the external ID is a database ID and thus a numeric value. Are you sure your external ID is `mark89` ? Does `SingleSignOnRecord.find_by(external_id: 'mark89')` return a database record?

Theory #2:  
Your staging site does not have SSO enabled, which usually goes hand in hand with external ID’s. Are you sure external ID’s are present ?

---

<div class="post-metadata">

### Author: ![mpemburn](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mpemburn/32/178585_2.png) [@mpemburn](https://meta.discourse.org/u/mpemburn)
#### Post date: [June 17, 2020, 5:05pm UTC](https://meta.discourse.org/t/unable-to-get-user-by-external-id/154996/10 "2020-06-17T17:05:35Z")

</div>

Richard,

Okay, so the sandbox doesn’t have SSO set up but production does. I checked my user record on production and yes, the external ID is set, and it is, in fact, a numeric ID. When I tested with the production credentials and URI and the real external ID, it returns the same 404 error.

Oh, and I’m not sure how to test SingleSignOnRecord.find\_by(external\_id: ‘mark89’). Where is this facility?

Mark

---

<div class="post-metadata">

### Author: ![RGJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rgj/32/523185_2.png) [@RGJ](https://meta.discourse.org/u/RGJ)
#### Post date: [June 17, 2020, 6:22pm UTC](https://meta.discourse.org/t/unable-to-get-user-by-external-id/154996/11 "2020-06-17T18:22:27Z")

</div>

> [@mpemburn](#):
>
> Where is this facility?

```
cd /var/discourse
./launcher enter app
rails c
SingleSignOnRecord.find_by(external_id: ‘mark89’)

```
