How to add pagination logic when we are calling a subworkflow which does api call?

I have a subworkflow which does some api call and performs some data modification and send me the result back . now in main flow i want to use this subworkflow and handle pagination as well .

What is the best way we can do this in n8n?

Hey @mylearnings_abu,
Since the Execute Workflow node passes data in a single batch execution-

1. Loop in the Main Workflow -Keep your subworkflow completely stateless. It accepts a page or offset parameter from the main flow, hits the API exactly once, and returns that single page of data.

  • The Flow: Main Flow (Loop node) $\rightarrow$ Execute Workflow (passing current page) $\rightarrow$ If node (checks if data is empty or has_more is false). Loop back if true.

  • Pros: Easier to debug and prevents memory/timeout issues with large datasets.