# /users/by-external/ not working

**URL:** https://meta.discourse.org/t/users-by-external-not-working/57401
**Category:** Support
**Created:** [February 15, 2017, 4:09am UTC](https://meta.discourse.org/t/users-by-external-not-working/57401 "2017-02-15T04:09:44Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![Biarity](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/biarity/32/121215_2.png) [@Biarity](https://meta.discourse.org/u/Biarity)
#### Post date: [February 15, 2017, 4:09am UTC](https://meta.discourse.org/t/users-by-external-not-working/57401/1 "2017-02-15T04:09:45Z")

</div>

This route doesn’t seem to be working:

```
 /users/by-external/:external-id

```

It’s essential when using Disocurse as an SSO provider since you need to know the usernames of a user, given their external\_id. (And since usernames can change, I don’t want to manage storing them in my own database).

Any idea how to make it work? I tried appending `.json` with no luck.

---

<div class="post-metadata">

### Author: ![mpalmer](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mpalmer/32/45740_2.png) [@mpalmer](https://meta.discourse.org/u/mpalmer)
#### Post date: [February 15, 2017, 4:24am UTC](https://meta.discourse.org/t/users-by-external-not-working/57401/2 "2017-02-15T04:24:39Z")

</div>

What does “doesn’t seem to be working” mean? Anything in the logs?

---

<div class="post-metadata">

### Author: ![Biarity](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/biarity/32/121215_2.png) [@Biarity](https://meta.discourse.org/u/Biarity)
#### Post date: [February 15, 2017, 4:58am UTC](https://meta.discourse.org/t/users-by-external-not-working/57401/3 "2017-02-15T04:58:27Z")

</div>

Just shows an “Oops! That page doesn’t exist or is private.”.

Even on this site, my user id is `26582` (got it by `GET meta.discourse.org/users/biarity.json` under `user`:`id`).  
Performing `GET meta.discourse.org/users/by-external/26582` shows `Oops! That page doesn’t exist or is private.`

---

<div class="post-metadata">

### Author: ![mpalmer](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mpalmer/32/45740_2.png) [@mpalmer](https://meta.discourse.org/u/mpalmer)
#### Post date: [February 15, 2017, 5:02am UTC](https://meta.discourse.org/t/users-by-external-not-working/57401/4 "2017-02-15T05:02:32Z")

</div>

> [@Biarity](#):
>
> Oops! That page doesn’t exist or is private.

Are you passing a valid API key? What do the logs say about the exact reason for the auth failure?

---

<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: [February 15, 2017, 5:38am UTC](https://meta.discourse.org/t/users-by-external-not-working/57401/5 "2017-02-15T05:38:08Z")

</div>

The `external_id` for a user doesn’t exist on Discourse until you send it with the SSO parameters from the site that is acting as the SSO provider. This site doesn’t use SSO, so it won’t work here.

Once a user has an `external_id` you can get the user by making a `GET` request to `example.com/users/by-external/:external_id.json`.

---

<div class="post-metadata">

### Author: ![Biarity](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/biarity/32/121215_2.png) [@Biarity](https://meta.discourse.org/u/Biarity)
#### Post date: [February 15, 2017, 5:41am UTC](https://meta.discourse.org/t/users-by-external-not-working/57401/6 "2017-02-15T05:41:23Z")

</div>

I’m doing the same request on my self-hosted discourse site (which is set up as an SSO provider), and still getting the same `Oops! That page doesn’t exist or is private` error. I’m using the external\_id that’s been provided by discourse during SSO.

---

<div class="post-metadata">

### Author: ![Biarity](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/biarity/32/121215_2.png) [@Biarity](https://meta.discourse.org/u/Biarity)
#### Post date: [February 15, 2017, 5:46am UTC](https://meta.discourse.org/t/users-by-external-not-working/57401/7 "2017-02-15T05:46:27Z")

</div>

In my site, doing ( my `external_id` is 1):  
`GET http://[MY DISCOURSE SITE]/users/by-external/1.json?api_key=[MY API KEY]&api_username=[MY API USER]` still yields a 404.

There’s nothing new in the error logs.

---

<div class="post-metadata">

### Author: ![mpalmer](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mpalmer/32/45740_2.png) [@mpalmer](https://meta.discourse.org/u/mpalmer)
#### Post date: [February 15, 2017, 7:34am UTC](https://meta.discourse.org/t/users-by-external-not-working/57401/8 "2017-02-15T07:34:18Z")

</div>

Is your `external_id` `1`, or is your `user_id` 1? Can you show a dump of your `single_sign_on_records` table? Also, `external_id` is all about using _another_ site as the SSO provider; if you’re using Discourse as the SSO provider, as you stated, you don’t need `external_id` because you’d use the `user_id` from Discourse to lookup the user.

---

<div class="post-metadata">

### Author: ![Biarity](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/biarity/32/121215_2.png) [@Biarity](https://meta.discourse.org/u/Biarity)
#### Post date: [February 15, 2017, 8:18am UTC](https://meta.discourse.org/t/users-by-external-not-working/57401/9 "2017-02-15T08:18:36Z")

</div>

Seems I was confused by the term `external_id` since it was included in the data sent by discourse during SSO. Apparently it’s supposed to be external to me, not to discourse (which makes sense now).

Calling `GET /admin/users/:user-id` (where `user-id` is the `external-id` given by discourse earlier) works well.

On a side note, is there a way of doing this without having to supply the API key? That would make integration with my client easier.

---

<div class="post-metadata">

### Author: ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)
#### Post date: [June 8, 2024, 12:44pm UTC](https://meta.discourse.org/t/users-by-external-not-working/57401/10 "2024-06-08T12:44:55Z")

</div>

This topic was automatically closed after 2670 days. New replies are no longer allowed.
