13

I'm using the PyGithub library to invite new member to the organization. The issue I faced is the next: In the scenario, when I know only users primary email, how can I retrieve his username to proceed invite accordingly? I know it is possible through UI, but can't find the corresponding call through API. Please, assist!

million_miles
  • 199
  • 1
  • 2
  • 10

4 Answers4

21

Use github user search api for this . I tried the below one.

https://api.github.com/search/users?q=solankiarpit1997@gmail.com

Key name login is the username here. response:

{
  "total_count": 1,
  "incomplete_results": false,
  "items": [
    {
      "login": "arpit1997",
      "id": 10682054,
      "avatar_url": "https://avatars1.githubusercontent.com/u/10682054?v=3",
      "gravatar_id": "",
      "url": "https://api.github.com/users/arpit1997",
      "html_url": "https://github.com/arpit1997",
      "followers_url": "https://api.github.com/users/arpit1997/followers",
      "following_url": "https://api.github.com/users/arpit1997/following{/other_user}",
      "gists_url": "https://api.github.com/users/arpit1997/gists{/gist_id}",
      "starred_url": "https://api.github.com/users/arpit1997/starred{/owner}{/repo}",
      "subscriptions_url": "https://api.github.com/users/arpit1997/subscriptions",
      "organizations_url": "https://api.github.com/users/arpit1997/orgs",
      "repos_url": "https://api.github.com/users/arpit1997/repos",
      "events_url": "https://api.github.com/users/arpit1997/events{/privacy}",
      "received_events_url": "https://api.github.com/users/arpit1997/received_events",
      "type": "User",
      "site_admin": false,
      "score": 52.297474
    }
  ]
}
Arpit Solanki
  • 9,567
  • 3
  • 41
  • 57
  • 2
    If the username `nateshmbhat1` has a public email address `nateshmbhatofficial@gmail.com` the only he can be found through API. I saw the profile, I think this user has email addresses private in his profile – Arpit Solanki Jul 16 '18 at 13:55
10

PyGithub API

Refer to search_users.

search_users(query, sort=NotSet, order=NotSet, **qualifiers)

  • query – string
  • sort – string (‘followers’, ‘repositories’, ‘joined’)
  • order – string (‘asc’, ‘desc’)
  • qualifiers – keyword dict query qualifiers

For example,

g = github.Github("USERNAME", "PASSWORD")
users = g.search_users("franky in:email")
for user in users:
    print(user.login)  # print the selected users' username.

GitHub API

According to GitHub API Search users, you can specify only searching by public email using keyword in.

For example,

https://api.github.com/search/users?q=franky+in:email

Then, you'll only get users with "franky" in there emails.

YLJ
  • 2,940
  • 2
  • 18
  • 29
1

The user must have set a public email address. The primary email address can't be searched by rest api

shuming
  • 25
  • 6
  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community May 11 '23 at 04:52
-1

I have public email address on github, but not able to get my username passing the email address

-bash-4.2$ curl -i -s  https://api.github.com/search/users?q=kamu.raju@gmail.com
    HTTP/1.1 200 OK
    Server: GitHub.com
    Date: Sun, 09 May 2021 15:00:13 GMT
    Content-Type: application/json; charset=utf-8
    Cache-Control: no-cache
    Vary: Accept, Accept-Encoding, Accept, X-Requested-With
    X-GitHub-Media-Type: github.v3; format=json
    Access-Control-Expose-Headers: ETag, Link, Location, Retry-After, X-GitHub-OTP, X- 
    RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Resource, X- 
    RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub- 
    Media-Type, Deprecation, Sunset
    Access-Control-Allow-Origin: *
    Strict-Transport-Security: max-age=31536000; includeSubdomains; preload
    X-Frame-Options: deny
    X-Content-Type-Options: nosniff
    X-XSS-Protection: 0
    Referrer-Policy: origin-when-cross-origin, strict-origin-when-cross-origin
    Content-Security-Policy: default-src 'none'
    X-RateLimit-Limit: 10
    X-RateLimit-Remaining: 8
    X-RateLimit-Reset: 1620572473
    X-RateLimit-Resource: search
    X-RateLimit-Used: 2
    Accept-Ranges: bytes
    Content-Length: 73
    X-GitHub-Request-Id: 8CAA:5135:2353C0C:3D598CC:6097F908

    {
    "total_count": 0,
    "incomplete_results": false,
    "items": [

     ]
     }

enter image description here