> ## Documentation Index
> Fetch the complete documentation index at: https://cometchat-22654f5b-docs-angular-v5-docs-update.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Retrieve Group Members

> Retrieve Group Members — CometChat documentation.

## 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.

1. `set(limit: Int)` - This method sets the limit i.e. the number of members that should be fetched in a single iteration.

<Tabs>
  <Tab title="Swift">
    ```swift theme={null}
    let groupMembersRequest = GroupMembersRequest.GroupMembersRequestBuilder(guid: guid)
    .set(limit: 30)
    .build();
    ```
  </Tab>
</Tabs>

2. `set(searchKeyword: String)` - This method allows you to set the search string based on which the group members are to be fetched.

<Tabs>
  <Tab title="Swift">
    ```swift theme={null}
    let groupMembersRequest = GroupMembersRequest.GroupMembersRequestBuilder(GUID: guid)
    .set(limit: 30)
    .set(searchKeyword : "abc")
    .build();
    ```
  </Tab>
</Tabs>

3. `set(scopes: [String])` - This method allows you to fetch group members based on multiple scopes.

<Tabs>
  <Tab title="Swift">
    ```swift theme={null}
    let groupMembersRequest = GroupMembersRequest.GroupMembersRequestBuilder(GUID: guid)
    .set(limit: 30)
    .set(scopes : ["admin","participant"])
    .build();
    ```
  </Tab>
</Tabs>

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.

<Tabs>
  <Tab title="Swift">
    ```swift theme={null}
    let limit = 10;
    let guid = "cometchat-guid-11"

    let groupMembersRequest = GroupMembersRequest.GroupMembersRequestBuilder(guid: guid).set(limit: limit).build();

    groupMembersRequest.fetchNext(onSuccess: { (groupMembers) in

      for member in groupMembers {

         print("Group Member fetched successfully. " + member.stringValue())
      }

    }) { (error) in

       print("Group Member list fetching failed with error:" + error!.errorDescription);
    }
    ```
  </Tab>

  <Tab title="Objective C">
    ```objc theme={null}
    NSString *guid = @"cometchat-guid-101";
    NSInteger limit = 30;
    GroupMembersRequest *groupMemberRequest = [[[[GroupMembersRequestBuilder alloc]initWithGuid:guid] setLimitWithLimit:limit] build];

    [groupMemberRequest fetchNextOnSuccess:^(NSArray<GroupMember *> * groupMembers) {

        // received group members list
        
        for (GroupMember *member in groupMembers) {
            
            // member
            NSLog(@"Group Member fetched successfully: %@",[member stringValue]);
        }
        
    } onError:^(CometChatException * error) {
        
        // Error
        NSLog(@"Group Member list fetching failed with exception: %@",[error ErrorDescription]);
        
    }];
    ```
  </Tab>
</Tabs>
