Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to retrieve multiple users at once with the GitHub API?

I'm able to get a single user, or all users created since a timestamp, or where there is some search match with the GitHub API.

https://developer.github.com/v3/users/#get-a-single-user https://developer.github.com/v3/users/#get-all-users https://developer.github.com/v3/search/#search-users

What I haven't been able to figure out is if there is a way to send something like a list of logins and get back all of those users at once.

My use case is that I'm pulling back a list of members off of an org. This provides me with enough data that I could loop through each individual user and get the detailed user data that I need this way, but I would rather not be hammering GitHub's API with a bunch of extra requests if it is not necessary.

like image 419
bigtunacan Avatar asked May 12 '17 04:05

bigtunacan


1 Answers

Using GraphQL API v4, you could build a dynamic query with as many user you have in your array & use aliases for each one :

query {
  user1: user(login: "aisalmi") {
    ...UserFragment
  }
  user2: user(login: "bertrandmartel") {
    ...UserFragment
  }
  user3: user(login: "molokoloco") {
    ...UserFragment
  }
}

fragment UserFragment on User {
  login
  name
}

I also use a fragment to avoid field duplication

Test it in the explorer

like image 125
Bertrand Martel Avatar answered Oct 08 '22 01:10

Bertrand Martel