GitHub API provides a way to get the members of an organization. I am the admin/owner for my organization and I would like to get the email addresses of all the users. I tried with the members
API but it does not return the email addresses.
Using curl with my admin auth-token
:
GET /orgs/my-org/members
I get the response that look like this(for one of the users)
"login": "auny",
"id": some-number,
"avatar_url": "https://secure.gravatar.com/avatar/6579d09c459f1adad8a60463f47eadd3?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png",
"gravatar_id": "6579d09c459f1adad8a60463f47eadd3",
"url": "https://api.github.com/users/auny",
"html_url": "https://github.com/auny",
"followers_url": "https://api.github.com/users/auny/followers",
"following_url": "https://api.github.com/users/auny/following{/other_user}",
"gists_url": "https://api.github.com/users/auny/gists{/gist_id}",
"starred_url": "https://api.github.com/users/auny/starred{/owner}
{/repo}",
"subscriptions_url": "https://api.github.com/users/auny/subscriptions",
"organizations_url": "https://api.github.com/users/auny/orgs",
"repos_url": "https://api.github.com/users/auny/repos",
"events_url": "https://api.github.com/users/auny/events{/privacy}",
"received_events_url":
"https://api.github.com/users/auny/received_events",
"type": "User"
Strangely enough, this contains a wealth of information about the user but not one of the important ones i.e the email address of the user. Being the admin
I should be able to get the email address's of all my users.
The other user API only return my own email address i.e the email address of the account whose auth-token
is used in the request. API usage:
GET /user/emails
How can this be achieved? Is there way around it?
How To List All Public Repositories Belonging to a User? So, to list all public repos from a user, send a GET request to https://api.github.com/users/<USER-NAME>/repos , replacing with the actual user from whom you want to retrieve the repositories.
You can view a list of members in your enterprise who don't have an email address from a verified domain associated with their user account on GitHub.com. In the top-right corner of GitHub.com, click your profile photo, then click Your enterprises.
After fetching the list of org members, fetch the info for each member using this API endpoint:
/users/:user
This will return the e-mail address of the user you have specified in your request URL.
Using GraphQL API v4, you don't have to call a request per user. The following will get members of an organization with their email
(if provided in public profile) :
{
organization(login: "my-org") {
membersWithRole(first: 100) {
totalCount
edges {
node {
login
name
email
}
}
pageInfo {
endCursor
hasNextPage
}
}
}
}
Try it in the explorer
[edit 08/2020] Using membersWithRole
instead of deprecated members
field
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With