Latest Microsoft Graph package is installed but can't see NextPageRequest in UserCollectionResponse

Mj 0 Reputation points
2023-10-04T01:04:44.1933333+00:00

Lates Microsoft grapg nuget package is installed for my .net project (version 5.28.0) getting the list of users but for other pages have problem, base on documentation i can use the OdataNextLink address for paging , but can't see QueryParameters.Skiptoken for using in quaryparameter like this

var result = await graphClient.Users.GetAsync((requestConfiguration) =>
{
	requestConfiguration.QueryParameters.Top = 5;
	requestConfiguration.QueryParameters.Skiptoken = "skiptoken=RFNwdAIAAQAAAD8...AAAAAAAA";
});

or u.NextPageRequest.GetAsync() [type of u is UserCollectionResponse

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
13,480 questions
{count} votes

1 answer

Sort by: Most helpful
  1. CarlZhao-MSFT 46,316 Reputation points
    2023-10-05T09:22:55.48+00:00

    Hi @Mj

    You can use the PageIterator class to simplify the process of consuming paged collections. The PageIterator handles enumerating the current page and requesting subsequent pages automatically.

    // Get the first page of users with a page size of 5
    var users = await graphClient.Users
        .GetAsync(requestConfiguration =>
        {
            requestConfiguration.QueryParameters.Top = 5;
            requestConfiguration.QueryParameters.Select = new string[] { "id", "displayName" };
        });
    
    // Create a page iterator to iterate over all users
    var pageIterator = PageIterator<User, UserCollectionResponse>
        .CreatePageIterator(
            graphClient,
            users,
            // Callback executed for each user in the collection
            (user) =>
            {
                Console.WriteLine(user.DisplayName);
                return true; // Return true to continue the iteration
            });
    
    // Start the iteration
    await pageIterator.IterateAsync();
    

    Hope this helps.

    If the reply is helpful, please click Accept Answer and kindly upvote it. If you have additional questions about this answer, please click Comment.

    1 person found this answer helpful.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.