Tuesday, June 16, 2020

How to get specific page number in pagination of web api in Dynamic CRM


Please refer to my previous blog where I had demonstrated the pagination technique using web api.

The pagination parameters and functionality differ when dealing with FetchXML refer here for details.

What if you want to just fetch specific page instead of browsing "@odata.nextLink".


Here is a solution

STEP 1) Set header accordingly
httpRequest.setRequestHeader("Prefer""odata.maxpagesize=10");


STEP 2) Use skiptoken parameter in query to get specific page details 

For Page 1 (First Page)
api/data/v9.0/accounts?$select=name&$orderby=createdon desc&$skiptoken=<cookie pagenumber='1' />

or - with Skiptoken also we will get page 1

api/data/v9.0/accounts?$select=name&$orderby=createdon desc

For Page 2 (Second Page)

api/data/v9.0/accounts?$select=name&$orderby=createdon desc&$skiptoken=<cookie pagenumber='2' />


Note: If you specify any page-number that do not have any data you get empty collection values.




Let's analyse a typical response of "@odata.nextLink"

Little difficult to read so here is a decoded version


1 comment:

Anonymous said...

Thank You :)

You are a lifesaver !!!