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

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.

2 Likes

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
5 Likes

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

2 Likes

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.

3 Likes

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