Is it possible to get a user by its Discourse ID from the Discourse API?

AI-generated summary

The discussion revolves around retrieving a user by their Discourse ID via the API. zogstrip notes that while there’s no direct public route using the user ID, a staff-only route exists: https://meta.discourse.org/admin/users/174238.json. Mittineague agrees, highlighting the lack of a public ID-based route despite the stability of user IDs compared to usernames. simon adds that SSO users can use the /users/by-external/{$user_id}.json route, clarifying that the Discourse ID is not the same as the external ID, which comes from the SSO provider. simon further explains that for WordPress users, the WPDiscourse/utilities unctions::get_discourse_user($user_id) function can retrieve the Discourse user based on the WordPress user ID.

Hi. I guess all is in the title.

There is https://meta.discourse.org/u/canapin.json but I don’t think there’s a route that uses the user id.

There is only one route that works with an id and no username that I know of. (which seems odd to me because usernames can change whereas ids can’t.)

Anyway, it’s a staff-only route, eg.

https://meta.discourse.org/admin/users/174238.json

If you are using SSO, there is the /users/by-external/{$user_id}.json route.

Is the discourse ID equal to the external ID?

No, the external_id is the id that is provided in the SSO payload from the SSO provider site. If you are using the WP Discourse plugin, there is a function that you can use for this:

WPDiscourse\Utilities\Utilities::get_discourse_user($user_id)

$user_id in the function call is the WordPress user_id.