Graphql query to list user group details with user

You can create a user or user group using graphql query as per below doc: Use Users and Groups API - Harness.io Docs
Sometime you need to get the details of user group (maybe for security scan/validation), so you can use below query to list all the user sorted by user group:

{
  userGroups(limit:100){
    pageInfo{
      hasMore
      limit
      offset
      total
    }
    nodes{
      id
      name
       users(limit: 20, offset: 0) {
    pageInfo {
      total
      limit
      hasMore
      offset
    }
    nodes {
      name
      }
    }  
   }
 }
}

Sample output:

{
  "data": {
    "userGroups": {
      "pageInfo": {
        "hasMore": false,
        "limit": 100,
        "offset": 0,
        "total": 17
      },
      "nodes": [
        {
          "id": "xxxxxxxxxxxxxxxx",
          "name": "Account Administrator",
          "users": {
            "pageInfo": {
              "total": 3,
              "limit": 20,
              "hasMore": false,
              "offset": 0
            },
            "nodes": [
              {
                "name": "User1"
              },
              {
                "name": "User2"
              },
              {
                "name": "User3"
              }
            ]
          }
        },

You can also add these field to get more details about user or user group.
User:

User Group:

1 Like