Going to the next page of an API call

Hey @nielsk!

This looks like the Klarna API, is that correct? Would you mind sharing how you currently have your query set up?

It's possible to dynamically pass values as query parameters that either directly reference the properties on your table mentioned here, or get interpolated using additionalScope to work with a script that will return all pages at once, like the one described here.

You might also try something like

const maxPages = 20;
let allResults = [];
let nextCursor;

for(let i = 0; i < maxPages; i++){
   //get current page data
   const pageData = await klarnaQuery.trigger({
      additionalScope: {
        next_page: nextCursor
      }
    });

    //add pages results to total results
    allResults = allResults.concat(pageData.disputes);

    //grab next page cursor
    nextCursor = pageData.pagination.next_page;

    //check to see if there's another page, and if not exit loop
    if(nextCursor.length === 0) break;

    /* note:
     the conditional above is just a guess on my part,
     you'll likely want to see what the api returns when 
     there are no more pages and adjust it to match that
    */

}

return allResults;

As described in this thread you may also want to add something like the following as the definition for your next_page parameter in case it needs to be omitted at the start:

Hopefully that's helpful, please let me know if you're still running into issues!