Creating a dynamic group

This page explains how to create a dynamic group.

Before you begin

Perform the following tasks before proceeding with the information on this page:

Creating a dynamic group

The following is an example of creating a dynamic group:

REST

To create a group, call groups.create() with the email address, organization ID, query, and labels for the new group.

Python

def create_dynamic_group(customer_id, email, query):
  service = build_service()
  groupDef = {
      "parent": "customerId/{}".format(customer_id),
      "groupKey": {"id": email},
      "labels": {"cloudidentity.googleapis.com/groups.discussion_forum": ""},
      "dynamicGroupMetadata": {
          "queries": [
              {
                  "resourceType": "USER",
                  "query": "user.organizations.exists(org, org.department=='engineering')"
              }
          ]
      }
  }
  request = service.groups().create(body=groupDef)
  request.uri += "&initialGroupConfig=INITIAL_GROUP_CONFIG_UNSPECIFIED"
  response = request.execute()
  return response

What's next

After the dynamic group exists, you can retrieve it and list its memberships. For more information, refer to Retrieving a dynamic group and listing members.