groups.find()
This method allows you to find an existing group by ID.
Definition
client.groups.find(id: string,options: ?Object):Promise<Group,Error>
Parameters
Parameter | Type | Description |
---|---|---|
id | string | ID of the group to find |
options | ?Object | Options (described below) |
Options
Parameter | Type | Description |
---|---|---|
ignoreNotFound | ?boolean | When group does not exist: If true , return null; if false (default) throw an error |
includeMembers | ?boolean | Whether to ensure that User objects are fully loaded for all group members (default: false ) |
Returns
An error will be thrown if any of the arguments are invalid.
If the group is not found, an error will be thrown with err.code
equal to client.errors.NotFoundError.code
.
If the current user does not have permission to fetch the group (one example: if a user is no longer a member of that group), an error will be thrown with err.code
equal to client.errors.PermissionDeniedError.code
.
Otherwise, once the returned Promise
is resolved, you will have access to the Group.
Example
try {const group = await client.groups.find('some-group-id');console.log('found group:', group.displayName);if (!group.hasCurrentUser) {console.log('not a member of that group but can fetch it');}} catch (err) {if (err.code === client.errors.NotFoundError.code) {console.log('Group not found');} else if (err.code === client.errors.PermissionDeniedError.code) {console.log('Permission denied, likely not a member');} else {console.log('Error');}}