Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get_members() isn't returning emails for all users, despite showing up in the GIthub UI #2861

Open
brendan-snyk opened this issue Dec 13, 2023 · 6 comments

Comments

@brendan-snyk
Copy link

Hello,
I'm going a full organization get_members() and it's returning all the users. The problem is, i'm trying to tie the 'login' (their github username) over to email, specifically their corporate email address. However, most of our members are returning an empty email field. Despite showing in the GIthub Web UI.

Any ideas here?

@brendan-snyk
Copy link
Author

My code is as simple as:

from github import Github
access_token = <redacted>

# Initialize GitHub
g = Github(access_token)

# Name of the organization
org_name = 'test'

# Get the organization
org = g.get_organization(org_name)

# List all teams in the organization
members = org.get_members()
for member in members:
        print(f"- {member.login}")
        print(f"- {member.email}")

@gjabouley-invn
Copy link
Contributor

Hello

in order to get the mail from API, user needs to configure its email address as public.

in https://github.com/settings/profile
image

Needs to select in the drop down list the corporate email address, then hit save button

then you can access email using API

@brendan-snyk
Copy link
Author

I understand what you are saying there, however, if we do this:

url = "https://api.github.com/graphql"
h = {"Authorization": "bearer " + token}
    ext = 'externalIdentities(first:1, userName: "' + email + '") {'
    q1 = """
    query{
    organization(login: "snyk") {
     samlIdentityProvider {
"""
    q2 = """
         edges {
           node {
             user {
               login
             }
           }
         }
       }
     }
   }

 }
"""
    final = q1 + ext + q2
    r = requests.post(url, json={"query": final}, headers=h).json()
    edges = safeget(
        r, "data", "organization", "samlIdentityProvider", "externalIdentities", "edges"
    )

It indeed works. Can the non-GraphQL endpoint match the data returned by GraphQL endpoint?

@gjabouley-invn
Copy link
Contributor

i'm not GraphQL fluent, but it looks like you are reading data from the samlIdentityProvider endpoint.
It might be different from the public email address API data accessed when calling member.email

@Arlington1985
Copy link

I am running the following code snippet, it doesn't get me any member

from github import Github
import os

github = Github(
    base_url="https://GITHUB_ENDPOINT/api/v3",
    login_or_token=os.environ["GITHUB_TOKEN"],
)

organization=github.get_organization("MYORG")

members=[]
# List all teams in the organization
members = organization.get_members()
for member in members:
        print(f"- {member.login}")
        print(f"- {member.email}")

But running with GH CLI returns

gh api \                            
  -H "Accept: application/vnd.github+json" \
  -H "X-GitHub-Api-Version: 2022-11-28" \
  /orgs/MYORG/members

@gjabouley-invn
Copy link
Contributor

Your snippet works fine, using an access token with following permission: admin:org, repo, user, workflow
I just removed the base_url="https://GITHUB_ENDPOINT/api/v3", line

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants