Small guide on how to use SC Array Lists to overcome external API paging challenge

Hi there fellow Wapplers,

I had some challenge regarding the use of external api’s that limit the output to a certain amount and use paging to let you access all the requested data. And I always really enjoy it to find ready made solutions here on the community. So here we go.

So for instance you call https://somedomain.com/get_all_orders and you have 1000 orders in total. But the api returns 50 per page. And it helps you by providing a pager, something like this:
pager

I did notice some topics like this one:

And also Teodor’s correct suggestion:

That’s already possible using the Server Connect Array List component:

Working with Server Connect Array Lists Server-side Components

  • create an array list
  • set value for page to 1
  • do your api call with the page to the value of page
  • add result rows of orders to the array list
  • create while loop and in this example make an expression for the ‘next’ in the pager to not be equal to null, so it keeps repeating as long as the api returns a next page
    *in the while loop add 1 to the page
    *do the same api call as above, but each time around the page will increase with 1
    *add the rows to the array list
    *and at last get the values from the array list

That’s all!

Small edit: instead of Add in you should use Add all. Otherwise you get multiple lists.

2 Likes