Fetching Organization members who are owners using GraphQL

How can I find out if the user is an owner of the organization? I am using the following to get a list of members of a given organization -

query ($org: String!, $after: String) {

  organization(login: $org) {

    membersWithRole(first: 100, after: $after) {

      nodes {

        login

        name

      }

      pageInfo {

        hasNextPage

        endCursor

      }

    }

  }

}

This is one of the cases where the edges and nodes properties of the connection are more different than simply having a totalCount field. This query should work for you:

query ($org: String!, $after: String) {
  organization(login: $org) {
    membersWithRole(first: 100, after: $after) {
      edges {
        cursor
        node {
          login
          name
        }
        role
      }
    }
  }
}

I hope that helps!

3 Likes

Thanks, this is exactly what I was looking for.

Even I am using below code to Fetch Organization members list.

@lee-dohm - Is it also possible to get users based on their roles? For example, get me the list of owners for an organization.

Thanks, 

@galok73 Since there’s no filter options on the membersWithRole connection on Organization, no. You’ll have to get all the users and then filter them yourself.

1 Like

Thanks for confirming.

@lee-dohm The problem here is that the role will be either of ADMIN or MEMBER, in a situation where there are multiple admins how to we filter if the person is the creator/owner of the organization?

A member with the ADMIN role is an owner of the organization:

There isn’t any special status for the creator of the organization, they’re simply granted the ADMIN role (which shows as “Owner” in the UI) to begin with. Anyone who is granted the ADMIN role is on equal footing with everyone else who has the ADMIN role.

I hope that helps!