Fetching data from a paginated API response

Hi!
I'm currently trying to use a Workflow to fetch all the data from a paginated REST API call and store the results in an array. I found a working solution, but it only works in an app. When I try the same setup in Workflow, I get this error: Internal Error running a block: Error: An internal server error occurred

I've tried using .trigger() along the additionalScope without the Promise part, and it worked. My dataset is only 127 entries. Let me know if I can offer more information!

Non-working Workflow:

Working app:

Hey @Dany_Bouchard - thanks for posting about this! In Workflows, it's not possible to trigger a block from another block. Using a function instead should work for you https://docs.retool.com/docs/retool-workflows-reuse-functions :slightly_smiling_face: Can you try that out and let us know if it solves what you were looking to do?

That was it, thank you very much much!

Here's my tweaked code if anyone needs it, where queryNotion is a formula calling an API:

const fetchAll = (offset, records, has_more) => {
  if (!has_more) return records;

  return new Promise(resolve => {
    return queryNotion(offset).then(queryResult => {
      const newResults = records.concat(queryResult.data.results);
      return resolve(fetchAll(queryResult.data.next_cursor, newResults, queryResult.data.has_more));
    });
  });
};

return fetchAll(undefined, [], true)
1 Like