Stay organized with collectionsSave and categorize content based on your preferences.
Managing memberships for Google Groups
After a group exists, you can create memberships for it. This page explains
how to perform some fundamental membership operations with the
Cloud Identity Groups API. To learn how to create a Google Group, refer toCreating and searching for Google Groups.
Before you begin
Enable the Cloud Identity API.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM
role (roles/serviceusage.serviceUsageAdmin), which
contains theserviceusage.services.enablepermission.Learn how to grant
roles.
The following code shows you how to add a membership to a group.expiryDetailis an optional field that can be added to set an expiration
for the membership. The value ofpreferredMemberKeyis the member's email
address.
defcreate_google_group_membership(service,identity_source_id,group_id,member_key):param="&groupKey.id="+group_id+"&groupKey.namespace=identitysources/"+identity_source_idtry:lookupGroupNameRequest=service.groups().lookup()lookupGroupNameRequest.uri+=param# Given a group ID and namespace, retrieve the ID for parent grouplookupGroupNameResponse=lookupGroupNameRequest.execute()groupName=lookupGroupNameResponse.get("name")# Create a membership object with a memberKey and a single role of type MEMBERmembership={"preferredMemberKey":{"id":member_key},"roles":{"name":"MEMBER","expiryDetail":{"expireTime":"2021-10-02T15:01:23Z"}}}# Create a membership using the ID for the parent group and a membership objectresponse=service.groups().memberships().create(parent=groupName,body=membership).execute()print(response)exceptExceptionase:print(e)
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2026-06-11 UTC."],[],[]]