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.
Use thememberships.createmethod to add a member to a group.
Before using any of the request data,
make the following replacements:
GROUP_ID: The numeric ID of the group that you want to add a
member to. To find the ID of a single group, use thegroups.lookupmethod. To see all group IDs under a customer or namespace, use thegroups.listmethod.
MEMBER_ID: The ID of the member. For Google-managed entities, use the
member's email address. For external-identity-mapped entities, use a string that meets the
identity source's requirements.
ROLE_NAME: The name of the role that you want to grant to the member.
UseOWNER,MANAGER, orMEMBER.
PROJECT_ID: The alphanumeric ID of the
Google Cloud project that you want to use to make the request.
HTTP method and URL:
POST https://cloudidentity.googleapis.com/v1/groups/GROUP_ID/memberships
Copy the request body and open themethod reference page.
The APIs Explorer panel opens on the right side of the page.
You can interact with this tool to send requests.
Paste the request body in this tool, complete any other required fields, and clickExecute.
The response contains anOperationindicting the status of your request.
Finished operations contain the membership that was added. For example:
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)
List memberships of a Google Group
REST
Use thememberships.listmethod to list the members of a group.
Before using any of the request data,
make the following replacements:
GROUP_ID: The numeric ID of the group that you want
to list members for. To find the ID of a single group, use thegroups.lookupmethod. To see all group IDs under a customer or namespace, use thegroups.listmethod.
PROJECT_ID: The alphanumeric ID of the
Google Cloud project that you want to use to make the request.
HTTP method and URL:
GET https://cloudidentity.googleapis.com/v1/groups/GROUP_ID/memberships
To send your request, expand one of these options:
Open themethod reference page.
The APIs Explorer panel opens on the right side of the page.
You can interact with this tool to send requests.
Complete any required fields and clickExecute.
The response contains an array of all members in the group and their roles.
Python
The following code lists the memberships for a group:
deflist_google_group_memberships(service,group_id):param="&groupKey.id="+group_idtry:lookup_group_name_request=service.groups().lookup()lookup_group_name_request.uri+=paramlookup_group_name_response=lookup_group_name_request.execute()group_name=lookup_group_name_response.get("name")# List membershipsresponse=service.groups().memberships().list(parent=group_name).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 2025-09-04 UTC."],[[["\u003cp\u003eThis guide provides instructions on how to manage memberships for existing Google Groups using the Cloud Identity Groups API.\u003c/p\u003e\n"],["\u003cp\u003eYou can add members to a Google Group by using the \u003ccode\u003ememberships.create\u003c/code\u003e method, specifying the group ID, member ID, and the desired role (MEMBER, MANAGER, or OWNER).\u003c/p\u003e\n"],["\u003cp\u003eAdding members to a group involves sending a POST request with a JSON body containing the member's details and role to a specific URL using curl, Powershell, or APIs explorer.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003ememberships.list\u003c/code\u003e method allows you to retrieve a list of all members within a specific Google Group, including their roles, by sending a GET request.\u003c/p\u003e\n"],["\u003cp\u003eThere is a python example for how to create and list the members of a google group using the correct library, including the option to add an expiry to the membership.\u003c/p\u003e\n"]]],[],null,[]]