fmourtaza
fmourtaza

Reputation: 307

Microsoft 365 Graph Api returns only 100 group count

While fetching Microsoft 365 Groups using Graph Api (Permission type: Delegated) - I got only 100 Group Count (see below screenshot) - I believe this has to be with pagination however the how to get the next bunch of group ? (like nextlink)

IGraphServiceGroupsCollectionPage groupCollection = await graphClient.Groups.Request().GetAsync();
if (groupCollection?.Count > 0)
{}

enter image description here

Upvotes: 0

Views: 780

Answers (1)

Danstan
Danstan

Reputation: 1771

When using the SDK, here is how you can paginate the groups. Note I have added .Top(2) to get pagination on a few groups.

 var groups = new List<Group>();
 var groupsPage = await graphServiceClient.Groups.Request().Top(2).GetAsync();
 groups.AddRange(groupsPage.CurrentPage);
 while (groupsPage.NextPageRequest != null)
 {
    groupsPage = await groupsPage.NextPageRequest.GetAsync();
    groups.AddRange(groupsPage.CurrentPage);
 }

Upvotes: 1

Related Questions