Skip to main content
Quick Reference - Fetch groups:
Available via: SDK | REST API | UI Kits

Overview

In other words, as a logged-in user, how do I retrieve the list of groups I’ve joined and groups that are available? In order to fetch the list of groups, you can use the GroupsRequest class. To use this class i.e to create an object of the GroupsRequest class, you need to use the GroupsRequestBuilder class. The GroupsRequestBuilder class allows you to set the parameters based on which the groups are to be fetched.

GroupsRequestBuilder

The GroupsRequestBuilder class allows you to set the below parameters:

Set Limit

This method sets the limit i.e. the number of groups that should be fetched in a single iteration.
On SuccessfetchNext() with basic limit returns an array of Group objects:

Set Search Keyword

This method allows you to set the search string based on which the groups are to be fetched.
On SuccessfetchNext() with search filter returns an array of Group objects matching the keyword:

Joined Only

This method when used, will ask the SDK to only return the groups that the user has joined or is a part of.
On SuccessfetchNext() with joinedOnly(true) returns groups the user has joined, with additional fields:

Set Tags

This method accepts a list of tags based on which the list of groups is to be fetched. The list fetched will only contain the groups that have been tagged with the specified tags.
On SuccessfetchNext() with tags filter returns groups matching the specified tags:

With Tags

This property when set to true will fetch tags data along with the list of groups.
On SuccessfetchNext() with withTags(true) returns groups including the tags field:
Finally, once all the parameters are set to the builder class, you need to call the build() method to get the object of the GroupsRequest class. Once you have the object of the GroupsRequest class, you need to call the fetchNext() method. Calling this method will return a list of Group objects containing n number of groups where n is the limit set in the builder class. The list of groups fetched will only have the public and password type groups. The private groups will only be available if the user is a member of the group.
On SuccessfetchNext() returns an array of Group objects. See the filter-specific Response accordions above for field details based on your query configuration.

Retrieve Particular Group Details

In other words, as a logged-in user, how do I retrieve information for a specific group? To get the information of a group, you can use the getGroup() method.
On SuccessgetGroup() returns a Group object:
It returns Group object containing the details of the group.

Get online group member count

To get the total count of online users in particular groups, you can use the getOnlineGroupMemberCount() method.
On SuccessgetOnlineGroupMemberCount() returns an object with GUID as key and online count as value:Example: {"tg1": 2}
This method returns a JSON Object with the GUID as the key and the online member count for that group as the value.

Best Practices

Always use fetchNext() with a reasonable setLimit() value (e.g., 20-30) rather than fetching all groups at once. This improves performance and reduces memory usage.
The GroupsRequest object maintains an internal cursor. Creating a new instance resets the cursor, causing the same page to be fetched repeatedly. Reuse the same instance across fetchNext() calls.
When displaying “My Groups” in your UI, use joinedOnly(true) to fetch only groups the user belongs to, rather than filtering the full list client-side.

Troubleshooting

Private groups are only returned if the logged-in user is a member. This is by design — use joinedOnly(true) to see all groups the user has access to, including private ones.
Verify the logged-in user session is active. Also check if filters like setTags or setSearchKeyword are too restrictive. Try removing filters to confirm groups exist.
Ensure the GUID exists in your CometChat app. GUIDs are case-sensitive — double-check the exact GUID string.

Next Steps

Create a Group

Create public, private, or password-protected groups

Join a Group

Join public or password-protected groups

Group Members

Manage members, roles, and permissions within groups

Send Messages

Send text, media, and custom messages to groups