Veja a seguir um exemplo de criação de um grupo dinâmico:
REST
Para criar um grupo dinâmico, chame
groups.create()
com uma instância do grupo. A instância do grupo precisa conter o
dynamicGroupMetadata com a consulta usada para preencher o grupo.
Python
Para criar um grupo dinâmico, chame o método service.groups().create com
uma instância do grupo. A instância do grupo precisa conter o
dynamicGroupMetadata com a consulta usada para preencher o grupo. O
exemplo a seguir mostra como criar um grupo dinâmico que contém todos os usuários
existentes no departamento de engenharia:
Veja a seguir um exemplo de atualização de um grupo dinâmico:
REST
Para atualizar um grupo dinâmico, chame groups.patch()
com uma instância do grupo. A instância do grupo precisa conter o
dynamicGroupMetadata com a nova consulta usada para preencher o grupo.
Python
Para atualizar um grupo dinâmico, chame o método service.groups().patch com
o nome do grupo a ser atualizado e uma instância do grupo. A instância
do grupo precisa conter o
dynamicGroupMetadata com a consulta usada para preencher o grupo. O
exemplo a seguir mostra como atualizar um grupo dinâmico que contém todos os usuários no
Engenharia para um grupo que contém todos os usuários nos departamentos de engenharia
ou finanças:
# 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
[[["Fácil de entender","easyToUnderstand","thumb-up"],["Meu problema foi resolvido","solvedMyProblem","thumb-up"],["Outro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Informações incorretas ou exemplo de código","incorrectInformationOrSampleCode","thumb-down"],["Não contém as informações/amostras de que eu preciso","missingTheInformationSamplesINeed","thumb-down"],["Problema na tradução","translationIssue","thumb-down"],["Outro","otherDown","thumb-down"]],["Última atualização 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)."]]