Search code examples
githubgithub-api

How to list the enterprise account owned organization in Github


How to list the Github enterprise account owned organizations using the Rest API. Rest API Doc - https://docs.github.com/en/enterprise-cloud@latest/rest/quickstart?apiVersion=2022-11-28.

Checked their doc, I cannot find the API to list the organizations owned by github enterprise account. Also, I need API to list all the users present in the enterprise account.


Solution

  • The list of organizations in an Github Enterprise Cloud or Server can be retrieved via the GraphQL API. There is no REST API endpoint to retrieve this data.

    Source: Github's Enterprise GraphQL documentation

    you can use the Enterprise Accounts API and the Audit Log API, which are only available as GraphQL APIs.

    Here is a sample GraphQL query that can retrieve the list of organizations within the Enterprise.

    query listOrganizationWithinEnterprise($enterprise_slug: String!) {
      enterprise(slug: $enterprise_slug) {
        name
        organizations(first:100){
          nodes{
            name
            ... on Organization{
              login
              name
            }
          }
        }
      }
    }
    

    Using a variables section {'enterprise_slug': 'your_enterprise_name_here'}.