Skip to content
Docs
Groups

List groups

List groups

zones.groups.list(strzone_id, GroupListParams**kwargs) -> GroupListResponse
GET/zones/{zoneId}/groups

Returns a paginated list of the groups in the specified zone. Use cursor pagination via after/before. Sort: comma-separated field list; prefix with - for descending (allowed: created_at, name, identifier). Pass expand[]=member_count to include each group's member count, expand[]=roles to include the identifiers of the roles assigned to each group, and expand[]=total_count to include the matching row count. Filter by exact identifier via filter[identifier] (repeatable, OR'd across values). Search via query[] (case-insensitive substring match, OR'd across repeated values); it matches the group's name and identifier. Pass filter[id] (repeatable, max 100) to restrict results to a known set of groups — mutually exclusive with after/before (returns 400 if combined). When filter[id] is set, limit is ignored and the response contains every requested group that exists in the zone, in a single page. IDs not in the zone are silently omitted.

ParametersExpand Collapse
zone_id: str
after: Optional[str]

Cursor for forward pagination

minLength1
maxLength255
before: Optional[str]

Cursor for backward pagination

minLength1
maxLength255
expand: Optional[Union[Literal["total_count", "member_count", "roles"], List[Literal["total_count", "member_count", "roles"]]]]
Accepts one of the following:
Literal["total_count", "member_count", "roles"]
Accepts one of the following:
"total_count"
"member_count"
"roles"
List[Literal["total_count", "member_count", "roles"]]
Accepts one of the following:
"total_count"
"member_count"
"roles"
filter_id: Optional[Union[str, SequenceNotStr[str]]]

Restrict results to groups with this ID. Repeatable, max 100. Mutually exclusive with after/before.

Accepts one of the following:
str

Restrict results to groups with this ID. Repeatable, max 100. Mutually exclusive with after/before.

SequenceNotStr[str]
filter_identifier: Optional[Union[str, SequenceNotStr[str]]]

Filter by exact group identifier

Accepts one of the following:
str

Filter by exact group identifier

SequenceNotStr[str]
limit: Optional[int]

Maximum number of items to return

minimum1
maximum100
query: Optional[Union[str, SequenceNotStr[str]]]

Search across name and identifier (substring match)

Accepts one of the following:
str

Search across name and identifier (substring match)

SequenceNotStr[str]
sort: Optional[str]

Comma-separated sort fields. Prefix with - for descending. Allowed: created_at, name, identifier

ReturnsExpand Collapse
class GroupListResponse:
items: List[Group]
id: str

Unique identifier of the group

created_at: datetime

Entity creation timestamp

formatdate-time
external: bool

Whether the group is synced from an external directory. When true the group is directory-owned and its membership is read-only; when false it is managed in Keycard. Read-only: set by external sync, never by the caller.

identifier: str

User-specified identifier, unique within the zone. Automatically assigned for groups from an external directory.

name: str

Human-readable group name

organization_id: str

Organization this group belongs to

updated_at: datetime

Entity update timestamp

formatdate-time
zone_id: str

Zone this group belongs to

member_count: Optional[int]

Number of users in the group. Included only when requested via expand[]=member_count (group get or list).

roles: Optional[List[str]]

Identifiers of the roles assigned to the group; members inherit them. Deduped across scopes. Included only when requested via expand[]=roles (group get or list).

List groups

import os
from keycardai_api import KeycardAPI

client = KeycardAPI(
    api_key=os.environ.get("KEYCARD_API_API_KEY"),  # This is the default and can be omitted
)
groups = client.zones.groups.list(
    zone_id="zoneId",
)
print(groups.items)
{
  "items": [
    {
      "id": "id",
      "created_at": "2019-12-27T18:11:19.117Z",
      "external": true,
      "identifier": "identifier",
      "name": "name",
      "organization_id": "organization_id",
      "updated_at": "2019-12-27T18:11:19.117Z",
      "zone_id": "zone_id",
      "member_count": 0,
      "roles": [
        "string"
      ]
    }
  ],
  "pagination": {
    "after_cursor": "x",
    "before_cursor": "x",
    "total_count": 0
  }
}
Returns Examples
{
  "items": [
    {
      "id": "id",
      "created_at": "2019-12-27T18:11:19.117Z",
      "external": true,
      "identifier": "identifier",
      "name": "name",
      "organization_id": "organization_id",
      "updated_at": "2019-12-27T18:11:19.117Z",
      "zone_id": "zone_id",
      "member_count": 0,
      "roles": [
        "string"
      ]
    }
  ],
  "pagination": {
    "after_cursor": "x",
    "before_cursor": "x",
    "total_count": 0
  }
}