Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GitHub API: List a users teams within an organization

In GitHub when viewing my organization's user list I'm able to see how many teams a user is a member of.

Clicking on this count shows me which teams a user is in, putting me on the following page: https://github.com/orgs/my-org/teams?query=%40username

However, I'm trying to achieve the same functionality via the GitHub API, but I've been unable to find an endpoint that lists what teams (within an organization) a user is currently a member of.

One workaround is to loop through all the teams in an organization and get their members list, but this can quickly go through my rate limit, so to be able to do this in one request would be useful.

like image 913
Seb Avatar asked May 26 '15 19:05

Seb


1 Answers

You can do this with GraphQL API v4 filtering users in teams within an organization with userLogins :

{
  organization(login: "my-org") {
    teams(first: 100, userLogins: ["johndoe"]) {
      totalCount
      edges {
        node {
          name
          description
        }
      }
    }
  }
}

which gives for instance :

{
  "data": {
    "organization": {
      "teams": {
        "totalCount": 2,
        "edges": [
          {
            "node": {
              "name": "Employees",
              "description": "org employees"
            }
          },
          {
            "node": {
              "name": "Developers",
              "description": "active developers"
            }
          }
        ]
      }
    }
  }
}

Source : platform.github.community forum

like image 103
Bertrand Martel Avatar answered Sep 30 '22 15:09

Bertrand Martel