Das folgende Beispiel zeigt die Erstellung einer dynamischen Gruppe:
REST
Rufen Sie zum Erstellen einer dynamischen Gruppe groups.create() mit einer Instanz der Gruppe auf. Die Instanz der Gruppe muss die dynamicGroupMetadata mit der Abfrage enthalten, die zum Befüllen der Gruppe verwendet wird.
Python
Rufen Sie zum Erstellen einer dynamischen Gruppe die Methode service.groups().create mit einer Instanz der Gruppe auf. Die Instanz der Gruppe muss die dynamicGroupMetadata mit der Abfrage enthalten, die zum Befüllen der Gruppe verwendet wird. Im folgenden Beispiel wird gezeigt, wie Sie eine dynamische Gruppe mit allen Nutzern in der Engineeringabteilung erstellen:
Das folgende Beispiel zeigt die Aktualisierung einer dynamischen Gruppe:
REST
Rufen Sie zum Aktualisieren einer dynamischen Gruppe groups.patch() mit einer Instanz der Gruppe auf. Die Instanz der Gruppe muss den dynamicGroupMetadata mit der neuen Abfrage enthalten, die zum Füllen einer neuen Gruppe verwendet wird.
Python
Rufen Sie zum Aktualisieren einer dynamischen Gruppe die Methode service.groups().patch mit dem Namen der zu aktualisierenden Gruppe und einer Instanz der Gruppe auf. Die Instanz der Gruppe muss die dynamicGroupMetadata mit der Abfrage enthalten, die zum Befüllen der Gruppe verwendet wird. Im folgenden Beispiel wird gezeigt, wie Sie eine dynamische Gruppe mit allen Nutzern im Engineering auf eine Gruppe aktualisieren, die alle Nutzer in den Abteilungen Engineering oder Finanzen enthält:
# name (i.e. groups/01234abcdeef) uniquely identifies the groupdefupdate_dynamic_group(name,query):service=build_service()groupDef={"dynamicGroupMetadata":{"queries":[{"resourceType":"USER","query":"user.organizations.exists(org, org.department=='engineering' || org.department=='finance')"}]}}request=service.groups().patch(name=name,body=groupDef)request.uri+="&updateMask=dynamicGroupMetadata"response=request.execute()returnresponse
[[["Leicht verständlich","easyToUnderstand","thumb-up"],["Mein Problem wurde gelöst","solvedMyProblem","thumb-up"],["Sonstiges","otherUp","thumb-up"]],[["Schwer verständlich","hardToUnderstand","thumb-down"],["Informationen oder Beispielcode falsch","incorrectInformationOrSampleCode","thumb-down"],["Benötigte Informationen/Beispiele nicht gefunden","missingTheInformationSamplesINeed","thumb-down"],["Problem mit der Übersetzung","translationIssue","thumb-down"],["Sonstiges","otherDown","thumb-down"]],["Zuletzt aktualisiert: 2025-08-18 (UTC)."],[[["\u003cp\u003eDynamic groups are available to specific Google Workspace and Cloud Identity premium accounts, with a limit of 500 per customer, which can be increased by contacting Google Workspace Support.\u003c/p\u003e\n"],["\u003cp\u003eCreating a dynamic group involves calling the \u003ccode\u003egroups.create()\u003c/code\u003e method (REST) or \u003ccode\u003eservice.groups().create\u003c/code\u003e (Python), ensuring the \u003ccode\u003edynamicGroupMetadata\u003c/code\u003e contains the query to populate the group.\u003c/p\u003e\n"],["\u003cp\u003eUpdating a dynamic group requires using \u003ccode\u003egroups.patch()\u003c/code\u003e (REST) or \u003ccode\u003eservice.groups().patch\u003c/code\u003e (Python), and includes modifying the \u003ccode\u003edynamicGroupMetadata\u003c/code\u003e with a new query.\u003c/p\u003e\n"],["\u003cp\u003eBefore creating or updating dynamic groups, users must set up Cloud Identity and familiarize themselves with the Groups API, dynamic groups overview, and set up the Groups API.\u003c/p\u003e\n"]]],[],null,["# Creating and updating a dynamic group\n=====================================\n\nThis page explains how to create and update a dynamic group.\n| **Note:** Dynamic groups are only available to Google Workspace Enterprise Standard, Enterprise Plus, Enterprise for Education, and Cloud Identity premium accounts. You can create up to 500 dynamic groups per customer. This limit can be increased on a case-by-case basis---contact [Google Workspace Support](https://support.google.com/a/answer/1047213) with your specific use case to request an increase.wss\n\nBefore you begin\n----------------\n\n| **Note:** Before you use any of the Cloud Identity APIs, you must set up Cloud Identity. See [Setting up Cloud Identity](/identity/docs/set-up-cloud-identity-admin) for instructions.\n\nPerform the following tasks before proceeding with the information on this page:\n\n- Read the [Groups API overview](/identity/docs/groups).\n\n- Read the [dynamic groups overview](/identity/docs/concepts/overview-dynamic-groups).\n\n- [Set up the Groups API](/identity/docs/how-to/setup).\n\n- (Optional) [Formulate and test a membership query](/identity/docs/how-to/test-query-dynamic-groups).\n\nCreating a dynamic group\n------------------------\n\nThe following is an example of creating a dynamic group: \n\n### REST\n\n\nTo create a dynamic group, call\n[`groups.create()`](/identity/docs/reference/rest/v1/groups/create)\nwith an instance of the group. The instance of the group must contain the\n`dynamicGroupMetadata` with the query used to populate the group.\n\n### Python\n\nTo create a dynamic group, call the `service.groups().create` method with\nan instance of the group. The instance of the group must contain the\n`dynamicGroupMetadata` with the query used to populate the group. The\nfollowing sample shows how to create a dynamic group containing all users\nexisting in the Engineering department: \n\n def create_dynamic_group(customer_id, email, query):\n service = build_service()\n groupDef = {\n \"parent\": \"customerId/{}\".format(customer_id),\n \"groupKey\": {\"id\": email},\n \"labels\": {\"cloudidentity.googleapis.com/groups.discussion_forum\": \"\"},\n \"dynamicGroupMetadata\": {\n \"queries\": [\n {\n \"resourceType\": \"USER\",\n \"query\": \"user.organizations.exists(org, org.department=='engineering')\"\n }\n ]\n }\n }\n request = service.groups().create(body=groupDef)\n request.uri += \"&initialGroupConfig=EMPTY\"\n response = request.execute()\n return response\n\nUpdating a dynamic group\n------------------------\n\nThe following is an example of updating a dynamic group: \n\n### REST\n\n\nTo update a dynamic group, call\n[`groups.patch()`](/identity/docs/reference/rest/v1/groups/patch)\nwith an instance of the group. The instance of the group must contain the\n`dynamicGroupMetadata` with the new query used to populate the group.\n\n### Python\n\nTo update a dynamic group, call the `service.groups().patch` method with\nthe name of the group to update and an instance of the group. The instance\nof the group must contain the\n`dynamicGroupMetadata` with the query used to populate the group. The\nfollowing sample shows how to update a dynamic group containing all users in\nEngineering to a group containing all users in either Engineering or Finance\ndepartments: \n\n # name (i.e. groups/01234abcdeef) uniquely identifies the group\n def update_dynamic_group(name, query):\n service = build_service()\n groupDef = {\n \"dynamicGroupMetadata\": {\n \"queries\": [\n {\n \"resourceType\": \"USER\",\n \"query\": \"user.organizations.exists(org, org.department=='engineering' || org.department=='finance')\"\n }\n ]\n }\n }\n request = service.groups().patch(name=name, body=groupDef)\n request.uri += \"&updateMask=dynamicGroupMetadata\"\n response = request.execute()\n\n return response\n\nWhat's next\n-----------\n\nAfter the dynamic group exists, you can retrieve it and list its memberships.\nFor more information, refer to\n[Retrieving a dynamic group and listing members](/identity/docs/how-to/retrieve-list-dynamic-groups)."]]