Get github username by id

Solution 1:

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.

Solution 2:

There's no documented feature, nor undocumented ones that I know of, that expose the retrieval of the username from the id. From the GitHub API consumer perspective, the user id is an "implementation detail". The real key is the username.

From what I understand, you only require a batch of usernames given a list of ids. And this would be a one time only request, not a permanent need.

As your request seems legit and limited in its scope, you might get this answer directly from GitHub support by dropping them an email at [email protected].

Indeed, xpaulbettsx, a GitHubber, even tweeted about this:

Support@ is good for Anything you want to tell GitHub - bugs, features, high 5s; everything but security which go to security@