Stay organized with collections
Save and categorize content based on your preferences.
GroupsApp
This class provides access to Google Groups information. It can be used to query information such
as 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.`);
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 does
not 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 current
user 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 following scopes:
https://www.googleapis.com/auth/groups
getGroups()
Retrieves all the groups of which you are a direct member (or a pending member). This is an
empty list if you are not in any groups. Throws an exception if the group does not exist or if
you 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);}
Note that if you are a member of a group, B, which is itself a member of another group, A, then
you are indirectly subscribed to group A. Even though you receive copies of messages
sent to the "parent" group A, you are not actually subscribed to that group.
You can use Group.getRole(email) to determine if you are an existing or pending
member 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 following scopes:
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-12-02 UTC."],[[["\u003cp\u003eThe \u003ccode\u003eGroupsApp\u003c/code\u003e class in Apps Script allows you to access and manage Google Groups information, such as retrieving group details and membership status.\u003c/p\u003e\n"],["\u003cp\u003eYou can use \u003ccode\u003egetGroupByEmail()\u003c/code\u003e to retrieve a specific group by its email address and check if the current user is a member.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003egetGroups()\u003c/code\u003e retrieves all groups where the user is a direct or pending member, enabling actions like listing group email addresses.\u003c/p\u003e\n"],["\u003cp\u003eBoth methods require authorization with the \u003ccode\u003ehttps://www.googleapis.com/auth/groups\u003c/code\u003e scope for accessing Google Groups data.\u003c/p\u003e\n"]]],[],null,["GroupsApp\n\nThis class provides access to Google Groups information. It can be used to query information such\nas a group's email address, or the list of groups in which the user is a direct member.\n\nHere's an example that shows how many groups the current user is a member of:\n\n```javascript\nconst groups = GroupsApp.getGroups();\nLogger.log(`You belong to ${groups.length} groups.`);\n``` \n\nProperties\n\n| Property | Type | Description |\n|----------|--------------------------------------------|-------------|\n| `Role` | [Role](/apps-script/reference/groups/role) | |\n\nMethods\n\n| Method | Return type | Brief description |\n|----------------------------------------------------|------------------------------------------------|----------------------------------------------------------------------------------|\n| [getGroupByEmail(email)](#getGroupByEmail(String)) | [Group](/apps-script/reference/groups/group) | Retrieves the group having the specified email address. |\n| [getGroups()](#getGroups()) | [Group[]](/apps-script/reference/groups/group) | Retrieves all the groups of which you are a direct member (or a pending member). |\n\nDetailed documentation \n\n`get``Group``By``Email(email)` \nRetrieves the group having the specified email address. Throws an exception if the group does\nnot exist or if you do not have permission to see it.\n\nHere is an example that gets a group by its email address and outputs whether the current\nuser is a member. Before running, replace the sample email address with a real group's email.\n\n```javascript\nconst group = GroupsApp.getGroupByEmail('example@googlegroups.com');\nconst currentUser = Session.getActiveUser();\nif (group.hasUser(currentUser)) {\n Logger.log('You are a member of this group.');\n} else {\n Logger.log('You are not a member of this group.');\n}\n```\n\nParameters\n\n| Name | Type | Description |\n|---------|----------|---------------------------------------------|\n| `email` | `String` | The email address of the group to retrieve. |\n\nReturn\n\n\n[Group](/apps-script/reference/groups/group) --- The group with the specified email address.\n\nAuthorization\n\nScripts that use this method require authorization with one or more of the following [scopes](/apps-script/concepts/scopes#setting_explicit_scopes):\n\n- `https://www.googleapis.com/auth/groups`\n\n*** ** * ** ***\n\n`get``Groups()` \nRetrieves all the groups of which you are a direct member (or a pending member). This is an\nempty list if you are not in any groups. Throws an exception if the group does not exist or if\nyou do not have permission to see it.\n\nHere's an example of how to print the email address for every group the user belongs to:\n\n```javascript\nfunction showMyGroups() {\n const groups = GroupsApp.getGroups();\n let str = `You are in ${groups.length} groups: `;\n for (let i = 0; i \u003c groups.length; i++) {\n const group = groups[i];\n str = `${str + group.getEmail()} `;\n }\n Logger.log(str);\n}\n```\nNote that if you are a member of a group, B, which is itself a member of another group, A, then you are *indirectly* subscribed to group A. Even though you receive copies of messages sent to the \"parent\" group A, you are not actually subscribed to that group.\n\nYou can use [Group.getRole(email)](/apps-script/reference/groups/group#getRole(String)) to determine if you are an existing or pending\nmember of the returned groups.\n\nReturn\n\n\n[Group[]](/apps-script/reference/groups/group) --- The list of groups of which the user is a direct member.\n\nAuthorization\n\nScripts that use this method require authorization with one or more of the following [scopes](/apps-script/concepts/scopes#setting_explicit_scopes):\n\n- `https://www.googleapis.com/auth/groups`"]]