Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Copilot Lvl 3
Message 1 of 9

Fetching Organization members who are owners using GraphQL

Solved! Go to Solution.

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

      }

    }

  }

}

 

8 Replies
Solution
Community Manager
Message 2 of 9

Re: Fetching Organization members who are owners using GraphQL

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!

Copilot Lvl 2
Message 3 of 9

Re: Fetching Organization members who are owners using GraphQL

Thanks, this is exactly what I was looking for.

Copilot Lvl 3
Message 4 of 9

Re: Fetching Organization members who are owners using GraphQL

@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, 

Community Manager
Message 5 of 9

Re: Fetching Organization members who are owners using GraphQL

@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.

Copilot Lvl 3
Message 6 of 9

Re: Fetching Organization members who are owners using GraphQL

Thanks for confirming.

Copilot Lvl 2
Message 7 of 9

Re: Fetching Organization members who are owners using GraphQL

@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?

Community Manager
Message 8 of 9

Re: Fetching Organization members who are owners using GraphQL

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

 

Screen Shot 2019-11-04 at 8.00.43 AM.png

 

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!

Ground Controller Lvl 1
Message 9 of 9

Re: Fetching Organization members who are owners using GraphQL

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