Skip to main content
// Fetch groups list
const request = new CometChat.GroupsRequestBuilder()
  .setLimit(30).build();
const groups = await request.fetchNext();

// Get specific group details
const group = await CometChat.getGroup("GUID");

// Fetch only joined groups
const request = new CometChat.GroupsRequestBuilder()
  .setLimit(30).joinedOnly(true).build();

// Get online member count
const count = await CometChat.getOnlineGroupMemberCount(["GUID"]);

Retrieve List of Groups

Use GroupsRequestBuilder to fetch groups with filtering, searching, and pagination.

Set Limit

Sets the number of groups to fetch per request.
let limit = 30;
let groupsRequest = new CometChat.GroupsRequestBuilder()
                  	.setLimit(limit)
                  	.build();

Set Search Keyword

Filters groups by a search string.
let limit = 30;
let searchKeyword = "group";
let groupsRequest = new CometChat.GroupsRequestBuilder()
                  	.setLimit(limit)
                  	.setSearchKeyword(searchKeyword)
                  	.build();

Joined Only

When true, returns only groups the logged-in user has joined.
let limit = 30;
let groupsRequest = new CometChat.GroupsRequestBuilder()
                  	.setLimit(limit)
                  	.joinedOnly(true)
                  	.build();

Set Tags

Filters groups by specified tags.
let limit = 30;
let tags = ["tag1", "tag2"];
let groupsRequest = new CometChat.GroupsRequestBuilder()
                  	.setLimit(limit)
                  	.setTags(tags)
                  	.build();

With Tags

When true, includes tag data in the returned group objects.
let limit = 30;
let groupsRequest = new CometChat.GroupsRequestBuilder()
                  	.setLimit(limit)
                  	.withTags(true)
                  	.build(); 
After configuring the builder, call build() to get the GroupsRequest object, then call fetchNext() to retrieve groups.
The list only includes public and password-protected groups. Private groups appear only if the user is a member.
let limit = 30;
let groupsRequest = new CometChat.GroupsRequestBuilder()
                  	.setLimit(limit)
                  	.build();

groupsRequest.fetchNext().then(
groupList => {
  console.log("Groups list fetched successfully", groupList);
}, error => {
  console.log("Groups list fetching failed with error", error);
}
);
The fetchNext() method returns an array of Group objects. Access the response data using getter methods:
FieldGetterReturn TypeDescription
guidgetGuid()stringUnique group ID
namegetName()stringDisplay name of the group
typegetType()stringGroup type ("public", "private", or "password")
membersCountgetMembersCount()numberTotal number of members in the group
ownergetOwner()stringUID of the group owner
hasJoinedgetHasJoined()booleanWhether the logged-in user has joined this group

Retrieve Particular Group Details

Use getGroup() to fetch a specific group’s details by GUID.
const GUID = "GUID";
CometChat.getGroup(GUID).then(
group => {
  console.log("Group details fetched successfully:", group);
}, error => {
  console.log("Group details fetching failed with exception:", error);
}
);   
ParameterDescription
GUIDThe GUID of the group to fetch
Returns a Group object with the group’s details. The method returns a Group object. Access the response data using getter methods:
FieldGetterReturn TypeDescription
guidgetGuid()stringUnique group ID
namegetName()stringDisplay name of the group
typegetType()stringGroup type ("public", "private", or "password")
membersCountgetMembersCount()numberTotal number of members in the group
ownergetOwner()stringUID of the group owner
hasJoinedgetHasJoined()booleanWhether the logged-in user has joined this group

Get Online Group Member Count

Use getOnlineGroupMemberCount() to get the number of online members in specified groups.
let guids = ["cometchat-guid-1"];
CometChat.getOnlineGroupMemberCount(guids).then(
groupMemberCount => {
  console.log("Total online user for specified groups:", groupMemberCount);
}, error => {
  console.log("Online group member count fetching failed with error:", error);
}
);
Returns an object with GUIDs as keys and online member counts as values.

Next Steps

Create Group

Create public, private, or password-protected groups

Retrieve Group Members

Fetch and filter members of a specific group