Unable to GET user by External ID

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

1 Like

See How to reverse engineer the Discourse API

@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?

5 Likes

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!

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:

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'
6 Likes

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

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 ?

1 Like

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

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