APIs & Services
Getting Started
Paging
11min
all altrata graphql apis use a common pagination methodology if a query supports pagination, then you will only receive a subset of the results on that particular page however, all results will be available to you even if they are not returned upfront, you will simply need to go through each of the results pages to acquire all of the data how it works if a query supports pagination, then you will only retrieve a certain amount of results per page each altrata api has different page limits and default page sizes refer to the specific api documentation to find these limits if data is residing on another page, you will be returned a cursor value as part of your response so that it can be used to access the other pages finding page information to get a cursor value returned to you, will need to add the pageinforesponse as a subfield within the response structure you will also need to add the following subfields of pageinforesponse totalcount represent the total count of items that match the search criteria pageinfo it further nests additional pagination related details hasnextpage boolean indicating whether there are more pages of results available after the current page startcursor cursor pointing to the start of the current page endcursor cursor pointing to the next page of results example query query personpaginationexample { personkeywordsearch(filter {searchkeyword "bill gates"}) { items { firstname lastname } pageinforesponse { totalcount pageinfo { hasnextpage startcursor endcursor } } } } example response { "data" { "personkeywordsearch" { "items" \[ { "firstname" "william gates", "lastname" "gates" } ], "pageinforesponse" { "totalcount" 47, "pageinfo" { "hasnextpage" true, "startcursor" null, "endcursor" "altptr10" } } } } } the example response has been shortened in this guide, exact response will be longer if you run the query yourself the pageinforesponse results has informed us that the total amount of results returned for the query we ran is 47, however, not all results are on this page which is why hasnextpage has returned a boolean value of true, and endcursor has provided a string that will allow us to access the next page of results to access the next page of results, we will need to add the pageinfo object to our argument and supply value returned in endcursor as a value performing pagination to access the next page of results you will need to add the pageinfo to your argument and one of two subfields the pageinfo object supports two subfields that will take a cursor value as its input after fetches items after the specified cursor before fetches items before the specified cursor therefore, to access the next page, you will need to use the after subfield example query query personpaginationexample { personkeywordsearch( filter {searchkeyword "bill gates"} pageinfo {after "altptr10"} ) { items { firstname lastname } pageinforesponse { totalcount pageinfo { hasnextpage haspreviouspage startcursor endcursor } } } } example response { "data" { "personkeywordsearch" { "items" \[ { "firstname" "william gates", "lastname" "gates" } ], "pageinforesponse" { "totalcount" 47, "pageinfo" { "hasnextpage" true, "haspreviouspage" true, "startcursor" "altptr0", "endcursor" "altptr20" } } } } } as you can see in the above example response, we have returned the next page of results we can tell because the haspreviouspage subfield has returned a value of true, and startcursor has returned the previous page cursor value you will be able to continue looping through the results with the cursor until you have reached the last page of results limiting results as well as being able to move between pages, you will also be able to limit the results you get returned back to you in a page to do this you can utilise the first and last properties first fetches the first 'n' elements in the list example only return the first 10 items last fetches the last 'n' elements in the list example return the last 3 items of the results on a particular page first example of first 2 elements query personpaginationexample { personkeywordsearch( filter {searchkeyword "bill gates"} pageinfo {after "altptr10", first 2} ) { items { firstname lastname } pageinforesponse { totalcount pageinfo { hasnextpage haspreviouspage startcursor endcursor } } } } example of first 2 response { "data" { "personkeywordsearch" { "items" \[ { "firstname" "william", "lastname" "gates" }, { "firstname" "william", "lastname" "gates" } ], "pageinforesponse" { "totalcount" 47, "pageinfo" { "hasnextpage" true, "haspreviouspage" true, "startcursor" "altptr8", "endcursor" "altptr12" } } } } } as you can see in the example response, only two items have been returned per page last the first field returned the first items per page, the last field will return the last items per page imagine that the results are in an array the last field will loop backwards in that array and only return the specified amount of items in the array example imagine we had an array that held 5 values \[1, 2, 3, 4, 5] if we specified that we wanted only the last 2 elements to be returned, then only values 5 and 4 would be returned to us this is how the last field will work in graphql when using the last field, it is mandatory that you use the before field in conjunction with it example of last 2 elements query query personpaginationexample { personkeywordsearch( filter {searchkeyword "bill gates"} pageinfo {before "altptr10", last 2} ) { items { firstname lastname } pageinforesponse { totalcount pageinfo { hasnextpage haspreviouspage startcursor endcursor } } } } if you use the after field with last field instead of the before field, you will see the following error { "data" { "personkeywordsearch" null }, "errors" \[ { "path" \[ "personkeywordsearch" ], "data" null, "errortype" "error", "errorinfo" null, "locations" \[ { "line" 2, "column" 3, "sourcename" null } ], "message" "missing mandatory field 'before' @ persons" } ] }