Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Unanswered

Trying to understand pagination on Web API

(0) ShareShare
ReportReport
Posted on by 15

I have 5000+ account records to work with. I'm trying to create a nice paginated list of these accounts.

I've seen the documentation here: https://docs.microsoft.com/en-us/powerapps/developer/common-data-service/webapi/query-data-web-api but it seems a little limited.

I can set the number of items per page easily enough with the header Prefer: odata.maxpagesize=50

This provides then a @odata.nextLink to get the next page. Seems simple enough.

What if I want to skip ahead to page 5?

Looking at the query string in nextLink, I see it has the page number in a cookie value.

I've found I can do a request to accounts?$select=name&$skiptoken=<cookie pagenumber="5"> and this seems to work.

But is this right? It feels dirty, is there a better way?

Also, there's a few more basic details missing, like total number of pages. I can get a count of total accounts (and calculate the total number of pages) with $count=true but this is limited to 5000, so it won't be accurate. How would I skip to the last page in this scenario?

Any help in this regard would be greatly appreciated Am I on the right track? Is there some documentation somewhere I'm missing?

  • rndev Profile Picture
    rndev 15 on at
    RE: Trying to understand pagination on Web API

    Do you have an example on how this count can be achieved using aggregate? I'm having trouble understanding how this can be done reading the docs linked above.

    Edit:  Ok, found it reading through these docs: http://docs.oasis-open.org/odata/odata-data-aggregation-ext/v4.0/cs01/odata-data-aggregation-ext-v4.0-cs01.html#_Toc378326295

    You can do accounts?$apply=aggregate($count as AccountsCount) however this query also has a limit, which is 50000. I have more accounts than that. Luckily I can filter this by the ones I need for this list, which should lower the total to less than 10000, but obviously if this grows to more than 50000, this solution will no longer be valid. Is there no way to retrieve the real count? There must be.

  • Martin Donnelly Profile Picture
    Martin Donnelly 1,016 on at
    RE: Trying to understand pagination on Web API

    you can, of course, also run an aggregate fetch to get a count and do some math with it.

  • rndev Profile Picture
    rndev 15 on at
    RE: Trying to understand pagination on Web API

    I can do a little bit of "cheating", I can work out the real count of accounts by not setting a max page size, and just paging through until there's no results. It's not too lengthy to to do, and I can cache this result for a while, run the count every once in a while on a cron job, so there's no slow down for the end user, and they get a "last page" and "total results" number. It's really not ideal though. There is a potential that the last page changes before the cache updates. There must be a nice way to do this.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Trying to understand pagination on Web API

    My experience is on the API side but, my impression is that the end-of-list is unknowable until you get there.  You notice that the navigation on the bottom right of the list has a "home" arrow but no "end" one -- just next.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,375 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans