API Pagination Almost There

I'm new to Javascript. I'm using the example here

const pageLimit = 3; //to avoid infinite loops!
let page = 1;
let allData = [];

for(page; page < pageLimit; page++){
//fetch data
const currentPageData = await gethuduAssetsLayouts.trigger({additionalScope: {page}});

//append recently fetched data
allData = [...allData, ...currentPageData.data];
//allData = [allData, currentPageData.data];

//check if this is the last page and exit the loop if so
if(page === pageLimit) break;

if(page === pageLimit) console.log("Page limit reached");

return allData;

My API returns 25 results at a time. I have a total of 32. It does not provide any page numbers or total count or searching.

When I run the code I get the first 25 results and then an error "query7: currentPageData.data is undefined."

If I take the ... off the allData array, I can see the table show 25, then change to 8. I know this will not work because the ... is used to amend the array. But it does show me that is it looping.

Any help would be greatly appreciated. I know I'm close.

Hey @ZeroMHz!

Happy to help here. Does your API return any properties that might help us fetch the next page? A screenshot of your query's data property in the State tab of your left panel would be helpful if you'd like to take a look together!

The API docs tell me that they do not provide page numbers.

Ah got it! Separate from Retool, how would you otherwise specify in your API that you want the second set of results? Is there a key to input your page info?