Class GroupsApp Stay organized with collections Save and categorize content based on your preferences.
Page Summary
The
GroupsAppclass provides access to Google Groups information, such as a group's email address or the list of groups a user is a direct member of.The
getGroupByEmail(email)method retrieves a specific group by its email address.The
getGroups()method retrieves all groups of which the user is a direct member.Both methods require authorization with the
https://www.googleapis.com/auth/groupsscope.
This class provides access to Google Groups information. It can be used to query information suchas a group's email address, or the list of groups in which the user is a direct member.
Here's an example that shows how many groups the current user is a member of:
constgroups=GroupsApp.getGroups();Logger.log(`You belong to${groups.length} groups.`);
Properties
| Property | Type | Description |
|---|---|---|
Role | Role |
Methods
| Method | Return type | Brief description |
|---|---|---|
get | Group | Retrieves the group having the specified email address. |
get | Group[] | Retrieves all the groups of which you are a direct member (or a pending member). |
Detailed documentation
getGroupByEmail(email)
Retrieves the group having the specified email address. Throws an exception if the group doesnot exist or if you do not have permission to see it.
Here is an example that gets a group by its email address and outputs whether the currentuser is a member. Before running, replace the sample email address with a real group's email.
constgroup=GroupsApp.getGroupByEmail('example@googlegroups.com');constcurrentUser=Session.getActiveUser();if(group.hasUser(currentUser)){Logger.log('You are a member of this group.');}else{Logger.log('You are not a member of this group.');}
Parameters
| Name | Type | Description |
|---|---|---|
email | String | The email address of the group to retrieve. |
Return
Group — The group with the specified email address.
Authorization
Scripts that use this method require authorization with one or more of the followingscopes:
https://www.googleapis.com/auth/groups
getGroups()
Retrieves all the groups of which you are a direct member (or a pending member). This is anempty list if you are not in any groups. Throws an exception if the group does not exist or ifyou do not have permission to see it.
Here's an example of how to print the email address for every group the user belongs to:
functionshowMyGroups(){constgroups=GroupsApp.getGroups();letstr=`You are in${groups.length} groups: `;for(leti=0;i <groups.length;i++){constgroup=groups[i];str=`${str+group.getEmail()} `;}Logger.log(str);}
You can useGroup.getRole(email) to determine if you are an existing or pendingmember of the returned groups.
Return
Group[] — The list of groups of which the user is a direct member.
Authorization
Scripts that use this method require authorization with one or more of the followingscopes:
https://www.googleapis.com/auth/groups
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-12-11 UTC.