We are using Microsoft Graph API Beta version to retrieve all users from the Azure AD using below code. API returns only 100 users in the response and to use paginated response we tried NextPageRequest
property. But it always return null
for the NextPageRequest
property. And due to that it never enters to the while loop to retrieve rest of the users.
Beta SDK version: 4.0.1.0
Code:
List<User> usersList = new List<User>();
IGraphServiceUsersCollectionPage users = await graphClient.Users.Request().GetAsync();
// Add the first page of results to the user list
usersList.AddRange(users.CurrentPage);
// Fetch each page and add those results to the list
while (users.NextPageRequest != null)
{
users = await users.NextPageRequest.GetAsync();
usersList.AddRange(users.CurrentPage);
}
log.Info("Users count: " + usersList.Count.ToString());
return usersList;
Reference links that I followed:
- Microsoft Graph only returning the first 100 Users
- https://learn.microsoft.com/en-us/graph/api/user-list?view=graph-rest-1.0&tabs=csharp
Any help on this will be appreciated!