Many organizations regularly rotate Google Groups members. Manual registration and deletion is tedious, so you would want to automate it via API.
The Admin SDK (Directory API) is commonly introduced as a method for managing Google Groups members via API. However, the Admin SDK requires Google Workspace admin privileges, limiting the situations where it can be used.
This article introduces how to bulk manage Google Groups members using the Cloud Identity Groups API, which can be used even without admin privileges.
API Options
There are mainly two methods for managing Google Groups members via API.
Admin SDK (Directory API)
This is the most widely documented method.
To use it, one of the following is required:
- A Google Workspace admin account
- A service account + Domain-Wide Delegation (requires configuration in the admin console)
If you do not have admin privileges, 403 Forbidden is returned.
Cloud Identity Groups API
The Cloud Identity Groups API allows member operations without admin privileges if you are an owner or manager of the group. This article uses this method.
The differences between the two are summarized below.
| Admin SDK (Directory API) | Cloud Identity Groups API | |
|---|---|---|
| Admin privileges | Required | Not required |
| Group owner privileges | – | Required |
| Domain-Wide Delegation | Required when using service accounts | Not required |
| OAuth user authentication | Admins only | Owners/managers can use |
| API endpoint | admin.directory_v1 | cloudidentity.v1 |
| Member operations | members() | groups().memberships() |
Prerequisites
- You are an owner or manager of the target group
- You have a Google Cloud project
Steps
1. Enable the API
Enable the following API in the Google Cloud Console:
2. Create an OAuth Client ID
- Open Cloud Console -> “APIs & Services” -> “Credentials”
- Select “Create credentials” -> “OAuth client ID”
- Select “Desktop app” as the application type
- Download the JSON file after creation
Note: The “OAuth consent screen” also needs to be configured the first time. “Internal” is fine for the user type.
3. Python Script
Install the required libraries:
Getting the Member List
On the first run, a browser will open asking for Google account authentication. After authentication, the token is saved to a file, and subsequent runs will authenticate automatically.
Adding a Member
Deleting a Member
Deletion requires the membership’s name (internal ID), so use the information obtained from the list retrieval.
4. Bulk Replacement Implementation Example
In actual operations, bulk replacement of “deleting existing members and registering new members” is often needed. Below is an implementation example.
Notes
- Rate limits: Sending too many requests in a short time may result in throttling. We recommend adding intervals with
time.sleep() - OAuth token management: Access tokens are saved in
token.pickle. Add it to.gitignoreto avoid committing to Git - Client secret: Manage
client_secret.jsonwith similar caution - Scopes: The
cloud-identity.groupsscope includes both read and write. For read-only access,cloud-identity.groups.readonlycan be used
Related Articles and References
The following articles are also helpful for managing Google Groups using the Cloud Identity Groups API.
| Article | Authentication Method | Content |
|---|---|---|
| Operating Google Workspace Groups with Cloud Identity API (Qiita) | Service account + Domain delegation | General group CRUD operations |
| Managing Google Group Membership with a Custom Python Wrapper | Service account + Domain delegation | Python wrapper implementation, adding members with expiration |
| GAS for Adding/Removing Members from Google Groups with Cloud Identity | OAuth (GAS) | Implementation with Google Apps Script |
| Use the Google Cloud Identity API for Google Groups (Medium) | Service account + Domain delegation | Comprehensive explanation in English |
| Google Official Documentation | – | API reference |
Unlike the articles above, this article introduced a method that completes entirely with OAuth user authentication, without using service accounts or Domain-Wide Delegation. I hope this serves as a useful option for automating Google Groups member management in environments without admin privileges.
Summary
Even in environments without Google Workspace admin privileges, you can bulk manage members with owner/manager group permissions using the Cloud Identity Groups API. Since it completes with OAuth user authentication alone, there is no need to prepare service accounts or configure Domain-Wide Delegation.
The source code is published on the GitHub repository.