Does anyone know how can I obtain the “external_id” for a user from the api? I added an external_id at the sso login, but now when I query users, I do not see any “external_id” in the user hash returned by the API. I’m trying to use the external_id as a way to identify users from my database when processing a webhook.
AI-generated summary
In a discussion about retrieving user data via API using external IDs in the context of SSO, rossinboulder asked how to obtain a user’s external_id through the API after setting it during SSO login. simon replied that this can be done by making an authenticated GET request to https://discourse.example.com/u/by-external/{external_id}.json, referencing the official documentation. rossinboulder then added how to retrieve the external_id given a user_id: either by using the Discourse Ruby API method user_sso(user_id), or by sending an authenticated request to https://discourse.example.com/admin/users/{id}.json and extracting the external_id from the single_sign_on_record hash. They also clarified that single_sign_on_record (including external_id) is not returned when querying https://discourse.example.com/users/{username}.json, emphasizing the need to use the admin endpoint or Ruby API for this data.
Yes, this can be done by sending an authenticated GET request to https://discourse.example.com/u/by-external/{external_id}.json
This route is documented here: Discourse API Docs.
And to get the inverse (ie obtain the external_id given a user_id) you can either:
-
Use the Discourse Ruby API and call the method: user_sso(user_id)
-
Send an authenticated get request to:
https://discourse.example.com/admin/users/{id}.json
and look for hash key [“single_sign_on_record”][“external_id”]
Note that single_sign_on_record (and external_id) is NOT returned by a call to:
https://discourse.example.com/users/{username}.json