web
You’re offline. This is a read only version of the page.
close
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?

I have the same question (0)
  • Community Member Profile Picture
    on at

    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.

  • rndev Profile Picture
    15 on at

    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.

  • Martin Donnelly Profile Picture
    1,030 on at

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

  • rndev Profile Picture
    15 on at

    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.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 170 Super User 2025 Season 2

#2
#ManoVerse Profile Picture

#ManoVerse 61

#3
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 52 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans