Microsoft Graph maxing out at 1000 results in C#?

WardH 61 Reputation points


I am using Microsoft Graph but I am confused why I only get back 1000 results (I know there is more data) when I specify a number higher then 1000.

Any thoughts on how to fix? I only get back 1000 there is over 12000 in my result set. I was expecting based on my code to get 5000.

Here is my code below.



            var messages = await graphClient.Users[email_address].MailFolders.Inbox.Messages
                .OrderBy("receivedDateTime desc")
                .Filter("receivedDateTime ge 2020-06-30T14:00:00Z AND receivedDateTime lt 2021-06-30T14:00:00Z")
Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,796 questions
0 comments No comments
{count} votes

Accepted answer
  1. Glen Scales 4,431 Reputation points

    1000 is the maximum number of items per page so you need something like this from

    var messages = await graphClient.Me.Messages  
        .Header("Prefer", "outlook.body-content-type=\"text\"")  
        .Select(e => new {  
    var pageIterator = PageIterator<Message>  
            // Callback executed for each item in  
            // the collection  
            (m) =>  
                return true;  
            // Used to configure subsequent page  
            // requests  
            (req) =>  
                // Re-add the header to subsequent requests  
                req.Header("Prefer", "outlook.body-content-type=\"text\"");  
                return req;  
    await pageIterator.IterateAsync();  

    This will enumerate all the items in a the Folder so if you want to stop after 5000 you need to to put some logic to break after the number has been reached if you look at the second example on the docs page that gives an example of that.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful