How can I get external_id from the user object?

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?

إعجاب واحد (1)

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

Will have the SSO info:

4 إعجابات

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 :wink:

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/....

3 إعجابات

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.

إعجاب واحد (1)

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:

إعجابَين (2)

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. :wink: But I am endlessly grateful that Discourse has such a strong API!

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