How to loop a function to paginate?

I’m building a plugin that will import some data from a third-party API. It will import about 1000 records. The API can only return 250 records per call. Each call gives a nextLink object that sets the next url to call.

For example, if the first call is https://apiurl.com/reso/odata/Property?$count=true&$top=250&$expand=Media&$skip=250" then the response includes “@odata.nextLink”: “https://apiurl.com/reso/odata/Property?$count=true&$top=250&$expand=Media&$skip=250” to indicate the next url to call to get the next bath of records.

$top indicates how many records to return at once, and $skip indicates how many records to skip over.

If no @odata.nextLink is returned, that means you’ve paginated through all the records.

What would the function look like to keep making Curl calls until they’ve all been imported?

there are various methods that could be employed, but in general it would flow something like…

set nextLink to original load.
while nextLink is not null
load link
set nextLink to returned value or null
endwhile

Well, I like to think off skip as the offset

Offset = Number of Records Per Page * (Current Page - 1)

Total Pages = ceil(Total Count / Per Page)

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.