2

Is it possible to list all github's organizations with GitHub GraphQL API v4 like we did with REST API v3 ?

Follow a limited sample call :

$ curl https://api.github.com/organizations?since=32358551
[
  {
    "login": "NxtReader",
    "id": 32358576,
    "url": "https://api.github.com/orgs/NxtReader",
    "repos_url": "https://api.github.com/orgs/NxtReader/repos",
    "events_url": "https://api.github.com/orgs/NxtReader/events",
    "hooks_url": "https://api.github.com/orgs/NxtReader/hooks",
    "issues_url": "https://api.github.com/orgs/NxtReader/issues",
    "members_url": "https://api.github.com/orgs/NxtReader/members{/member}",
    "public_members_url": "https://api.github.com/orgs/NxtReader/public_members{/member}",
    "avatar_url": "https://avatars3.githubusercontent.com/u/32358576?v=4",
    "description": null
  },
  {
    "login": "fokkmandag",
    "id": 32358602,
    "url": "https://api.github.com/orgs/fokkmandag",
    "repos_url": "https://api.github.com/orgs/fokkmandag/repos",
    "events_url": "https://api.github.com/orgs/fokkmandag/events",
    "hooks_url": "https://api.github.com/orgs/fokkmandag/hooks",
    "issues_url": "https://api.github.com/orgs/fokkmandag/issues",
    "members_url": "https://api.github.com/orgs/fokkmandag/members{/member}",
    "public_members_url": "https://api.github.com/orgs/fokkmandag/public_members{/member}",
    "avatar_url": "https://avatars2.githubusercontent.com/u/32358602?v=4",
    "description": null
  }
]
Bertrand Martel
  • 42,756
  • 16
  • 135
  • 159
Luca G. Soave
  • 12,271
  • 12
  • 58
  • 109

1 Answers1

2

You can use a search query with type:org asĀ SearchResultItem can hold an Organization object :

{
  search(first: 100, type: USER, query: "type:org") {
    userCount
    pageInfo {
      hasNextPage
      endCursor
    }
    edges {
      node {
        ... on Organization {
          login
          name
          description
        }
      }
    }
  }
}

For the pagination, you can get the next request with after param as the last endCursor value if hasNextPage is true, like :

search(after: "Y3Vyc29yOjEwMA==", first: 100, type: USER, query: "type:org")
Bertrand Martel
  • 42,756
  • 16
  • 135
  • 159