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

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

      }

    }

  }

}

 

6 Replies
Solution
Community Manager
Message 2 of 7

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 7

Re: Fetching Organization members who are owners using GraphQL

Thanks, this is exactly what I was looking for.

Copilot Lvl 3
Message 4 of 7

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 7

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 7

Re: Fetching Organization members who are owners using GraphQL

Thanks for confirming.

Ground Controller Lvl 1
Message 7 of 7

Re: Fetching Organization members who are owners using GraphQL

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