0
votes

I have the following functions to get messages using Graph API

var client = new GraphServiceClient(authenticationProvider);
var messages = await client.Users["[email protected]"].Messages
     .Request()
     .GetAsync();

I am only able to get the latest 10 messages. How do I get all the messages? I tried to have a look at the microsoft documentation here: https://docs.microsoft.com/en-us/graph/api/message-get?view=graph-rest-1.0&tabs=csharp but unable to find any clues.

2
not the answer I am looking for. I have put a c# code not a URL one.jay

2 Answers

2
votes

Found the answer after googling and trial error.

IUserMessagesCollectionPage msgs = await _client.Users[[email protected]].Messages.Request()
                .Filter("put your filter here")
                .GetAsync();
            List<Message> messages = new List<Message>();
            messages.AddRange(msgs.CurrentPage);
            while (msgs.NextPageRequest != null)
            {
                await msgs.NextPageRequest.GetAsync();
                messages.AddRange(msgs.CurrentPage);
            }
0
votes

I think you should refer to this document:

Depending on the page size and mailbox data, getting messages from a mailbox can incur multiple requests. The default page size is 10 messages. To get the next page of messages, simply apply the entire URL returned in @odata.nextLink to the next get-messages request. This URL includes any query parameters you may have specified in the initial request.