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

Retrieve the List of Group Members

In order to fetch the list of groups members for a group, you can use the GroupMembersRequest class. To use this class i.e to create an object of the GroupMembersRequest class, you need to use the GroupMembersRequestBuilder class. The GroupMembersRequestBuilder class allows you to set the parameters based on which the groups are to be fetched. The GroupMembersRequestBuilder class allows you to set the below parameters: The GUID of the group for which the members are to be fetched must be specified in the constructor of the GroupMembersRequestBuilder class.

Set Limit

This method sets the limit i.e. the number of members that should be fetched in a single iteration.

Set Search Keyword

This method allows you to set the search string based on which the group members are to be fetched.

Set Scopes

This method allows you to fetch group members based on multiple scopes.

Set Status

The status based on which the group members are to be fetched. The status parameter can contain one of the below two values:
  • CometChat.USER_STATUS.ONLINE - will return the list of only online group members.
  • CometChat.USER_STATUS.OFFLINE - will return the list of only offline group members.
If this parameter is not set, will return all the group members regardless of their status.
Finally, once all the parameters are set to the builder class, you need to call the build() method to get the object of the GroupMembersRequest class. Once you have the object of the GroupMembersRequest class, you need to call the fetchNext() method. Calling this method will return a list of GroupMember objects containing n number of members where n is the limit set in the builder class.
On SuccessfetchNext() returns an array of GroupMember objects:GroupMember Object (per item in array):

Best Practices

Always use fetchNext() with a reasonable setLimit() value (e.g., 20-30). For groups with many members, paginate through results rather than fetching all at once.
The GroupMembersRequest object maintains an internal cursor. Creating a new instance resets the cursor. Reuse the same instance across fetchNext() calls.
Use setScopes() to fetch only admins or moderators when building admin management UIs, rather than fetching all members and filtering client-side.

Troubleshooting

Verify the GUID is correct and the logged-in user is a member of the group. Non-members cannot fetch the member list of private groups.
Ensure you’re reusing the same GroupMembersRequest instance. Creating a new builder resets the pagination cursor.

Next Steps

Add Members

Add new members to a group

Kick/Ban Members

Kick, ban, and unban group members

Change Member Scope

Update member roles within a group

Retrieve Groups

Fetch group lists and group details