Pagination : How to get complete data in response for a Graph API request using @odata.nextLink

Madhura Lodam 1 Reputation point
2022-12-19T14:33:27.243+00:00

I am getting the @odata.nextLink in my response, but what is the correct way to get the whole and complete response.
I cannot hit the api request everytime with the @odata.nextLink in the url because each time it returns me 100 records since I am using $expand query parameter and with this parameter even if I add $top=999 , it gives me 100 records only.

Here my data is in large amount , I will have to iterate over the response for n number of times, which is not ideal?

Can anyone please suggest if there is any other way to do that?

Thanks!

Microsoft Security Microsoft Graph
{count} votes

1 answer

Sort by: Most helpful
  1. Michael Taylor 60,161 Reputation points
    2022-12-19T15:30:16.44+00:00

    Paging is designed to return a limited set of data. You cannot "ask for it all" in most APIs. This is by design for APIs that can return large sets of data so the client and server do not get overwhelmed. Most APIs that support paging have an upper limit on how much you can request at once irrelevant of how much you ask for.

    You have to keep calling the API with the next link until you get all the data. This is how paging works and there is no workaround. You can read all about paging in the Graph API here. Note that the specifics of paging various by the resource the API is wrapping but in general if you ask for $top=X then the APi will return at most X records. If X is greater than what the underlying API allows it may either error or return the server-specified max results. This is by design and not something you can change.


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.