Get github username by id

We need to do this on Gitter to deal with the situation where a user has changed their username on GitHub and we get a 404 response when querying their old username.

Here’s an undocumented endpoint, so use as your own peril, but it does work for now.

Use the endpoint: https://api.github.com/user/:id, where :id is the ID of the user.

Similar endpoints exist for repos and orgs, at
https://api.github.com/repositories/:id and https://api.github.com/organizations/:id respectively.

Note that the new repository redirects preview API only supports repositories, not renamed users or organizations. In fact, the HTTP 301 redirect actually points to https://api.github.com/repositories/:id, so there’s a good chance that these “ID” endpoints may in fact become official soon.

Leave a Comment