Voici un exemple de création d'un groupe dynamique :
REST
Pour créer un groupe dynamique, appelez la méthode groups.create() accompagnée d'une instance de groupe. L'instance du groupe doit contenir l'élément dynamicGroupMetadata avec la requête utilisée pour renseigner le groupe.
Python
Pour créer un groupe dynamique, appelez la méthode service.groups().create avec une instance du groupe. L'instance du groupe doit contenir l'élément dynamicGroupMetadata avec la requête utilisée pour renseigner le groupe. L'exemple suivant montre comment créer un groupe dynamique contenant tous les utilisateurs existants du service d'ingénierie ("engineering") :
Voici un exemple de mise à jour d'un groupe dynamique :
REST
Pour mettre à jour un groupe dynamique, appelez la méthode groups.patch() accompagnée d'une instance de groupe. L'instance du groupe doit contenir l'élément dynamicGroupMetadata avec la nouvelle requête utilisée pour renseigner le groupe.
Python
Pour mettre à jour un groupe dynamique, appelez la méthode service.groups().patch accompagnée du nom du groupe à mettre à jour et d'une instance du groupe. L'instance du groupe doit contenir l'élément dynamicGroupMetadata avec la requête utilisée pour renseigner le groupe. L'exemple suivant montre comment mettre à jour un groupe dynamique contenant tous les utilisateurs du service d'ingénierie vers un groupe contenant tous les utilisateurs des services d'ingénierie et des finances :
# 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
Sauf indication contraire, le contenu de cette page est régi par une licence Creative Commons Attribution 4.0, et les échantillons de code sont régis par une licence Apache 2.0. Pour en savoir plus, consultez les Règles du site Google Developers. Java est une marque déposée d'Oracle et/ou de ses sociétés affiliées.
Dernière mise à jour le 2025/09/04 (UTC).
[[["Facile à comprendre","easyToUnderstand","thumb-up"],["J'ai pu résoudre mon problème","solvedMyProblem","thumb-up"],["Autre","otherUp","thumb-up"]],[["Difficile à comprendre","hardToUnderstand","thumb-down"],["Informations ou exemple de code incorrects","incorrectInformationOrSampleCode","thumb-down"],["Il n'y a pas l'information/les exemples dont j'ai besoin","missingTheInformationSamplesINeed","thumb-down"],["Problème de traduction","translationIssue","thumb-down"],["Autre","otherDown","thumb-down"]],["Dernière mise à jour le 2025/09/04 (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)."]]