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


(Coin-coin le Canapin) #1

Hi. I guess all is in the title.


(Régis Hanol) #2

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


(Mittineague) #3

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

(Simon Cossar) #4

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


(Coin-coin le Canapin) #5

Is the discourse ID equal to the external ID?


(Simon Cossar) #6

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.


(system) #7

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