Box.V2.Managers.BoxGroupsManager.GetAllGroupMembershipsForUserAsync C# (CSharp) Method

GetAllGroupMembershipsForUserAsync() public method

Get the list of group memberships for a given user.
public GetAllGroupMembershipsForUserAsync ( string userId, int limit = null, int offset = null, List fields = null, bool autoPaginate = false ) : Task>
userId string The id of the user to get the list of memberships for.
limit int The number of results to return with this request. Refer to the Box API for defaults.
offset int The offset of the results. Refer to the Box API for more details.
fields List Attribute(s) to include in the response.
autoPaginate bool Whether or not to auto-paginate to fetch all group memberships; defaults to false.
return Task>
        public async Task<BoxCollection<BoxGroupMembership>> GetAllGroupMembershipsForUserAsync(string userId, int? limit = null, int? offset = null,
                                                                                                List<string> fields = null, bool autoPaginate = false)
        {
            userId.ThrowIfNullOrWhiteSpace("userId");

            BoxRequest request = new BoxRequest(_config.UserEndpointUri, string.Format(Constants.GroupMembershipPathString, userId))
                .Param(ParamFields, fields)
                .Param("limit", limit.ToString())
                .Param("offset", offset.ToString());

            if (autoPaginate)
            {
                if (!limit.HasValue)
                {
                    limit = 100;
                    request.Param("limit", limit.ToString());
                }
                if (!offset.HasValue)
                    request.Param("offset", "0");

                return await AutoPaginateLimitOffset<BoxGroupMembership>(request, limit.Value);
            }
            else
            {
                IBoxResponse<BoxCollection<BoxGroupMembership>> response = await ToResponseAsync<BoxCollection<BoxGroupMembership>>(request).ConfigureAwait(false);
                return response.ResponseObject;
            }
        }