Google Apps Script

Class GroupsManager

This class allows administrators to create, update, retrieve and delete groups in a Google Apps domain.

To use this class you have to first enable the Provisioning API on your domain.

 
// This example creates a new group and adds the current user as an owner.
 var group = GroupsManager.createGroup('testgroup', 'my new group');
 group.addOwner(Session.getActiveUser().getEmail());
 

Properties

PropertyTypeDescription
PermissionLevelPermissionLevelThe permission level for various group management operations

Methods

MethodReturn typeBrief description
createGroup(groupId, name)DomainGroupCreates a new group for the Google Apps domain.
createGroup(groupId, name, description, permissionLevel)DomainGroupCreates a new group for the Google Apps domain.
getAllGroups()DomainGroup[]Retrieves the list of groups for the Google Apps domain.
getAllGroups(memberId)DomainGroup[]Retrieves the list of groups for a particular member.
getDomain()StringRetrieves the name of the domain being managed.
getGroup(groupId)DomainGroupRetrieves information about a single group for the Google Apps domain.

Detailed documentation

createGroup(groupId, name)

Creates a new group for the Google Apps domain.

 
// Creates a new group with ID 'testgroup' and name 'my new test group'.
 var group = GroupsManager.createGroup('testgroup', 'my new test group');
 

Parameters

NameTypeDescription
groupIdStringthe unique identifier of the new group
nameStringthe name of the new group

Return

DomainGroup — the newly created group


createGroup(groupId, name, description, permissionLevel)

Creates a new group for the Google Apps domain.

 
// Creates a new group with supplied description and permission level.
 var group = GroupsManager.createGroup('testgroup', 'my new test group',
                                       'This is a new example group.',
                                       GroupsManager.PermissionLevel.MEMBER);
 

Parameters

NameTypeDescription
groupIdStringthe unique identifier of the new group
nameStringthe name of the new group
descriptionStringthe general description of the new group
permissionLevelPermissionLevelthe permission level of the new group

Return

DomainGroup — the newly created group


getAllGroups()

Retrieves the list of groups for the Google Apps domain.

 
// Logs the names of all of the groups in the domain.
 var groups = GroupsManager.getAllGroups();
 for (var i in groups) {
   Logger.log(groups[i].getName());
 }
 

Return

DomainGroup[] — an array of objects representing all of the groups in the domain


getAllGroups(memberId)

Retrieves the list of groups for a particular member.

 
// Logs the names of the groups a member belongs to. 
 var groups = GroupsManager.getAllGroups('john.smith@example.com');
 for (var i in groups) {
   Logger.log(groups[i].getName());
 }
 

Parameters

NameTypeDescription
memberIdStringthe email address of the user or group to be removed from the group

Return

DomainGroup[] — an array of objects representing all groups the user is a member of


getDomain()

Retrieves the name of the domain being managed.

 
// Logs the name of the domain.
 Logger.log(GroupsManager.getDomain());
 

Return

String — the name of the domain being managed


getGroup(groupId)

Retrieves information about a single group for the Google Apps domain.

 
var group = GroupsManager.getGroup("testgroup@example.com");
 

Parameters

NameTypeDescription
groupIdStringthe unique identifier associated with the group to retrieve

Return

DomainGroup — a DomainGroup object representing the domain's group

Authentication required

You need to be signed in with Google+ to do that.

Signing you in...

Google Developers needs your permission to do that.