How to access all paginated Shopify Graph API products in the final code node instead of only the last page?

I have an n8n workflow where I’m fetching products from the Shopify Graph API using pagination. I check pageInfo.hasNextPage and keep requesting the next page until all products are fetched. The pagination itself works fine.

The problem is at the end of the workflow: in my final Code node, I only receive the products from the last page request, not all products from all pages. I want to process the complete product list together but it only gives me the last page products only.

What is the recommended way in n8n to:

  • Get results from all pagination requests into one array, and

  • Access that full dataset in a final node?

Is there a way to temporarily store data per workflow execution, or should this be handled differently using any other node?

Any best practices or examples would be really helpful.

Hi @Gladiator

What’s happening is that each pagination request is a separate execution of that branch, so your last Code node only sees the items from the last page that passed through it.

In n8n nothing is accumulated automatically across loop iterations. If you want all pages together at the end, you need to explicitly aggregate them.

The usual pattern is to collect each page’s products into items and then use a Merge node (mode: “Append”) after the loop. Send the output of every paginated request into that Merge node. It will keep appending the items from each page instead of replacing them.

After the pagination finishes, connect your final Code node to the output of that Merge node. At that point the Code node will receive one big list containing products from all pages, not just the last one.

If you prefer to build a single array, add one more Code node after the Merge and do something like taking all incoming items and mapping them into one array inside a single item. But the key step is the Merge in append mode to accumulate results from every page of the Shopify pagination.

Thanks Tamy. I did this but it still returns the last item response not all. The Merge1 node data is replaced on each iteration. In last code node I added this
return $(‘Merge1’).all();

Hi @Gladiator

thanks for sharing, I took a close look at your workflow.

Each pagination call runs the node from scratch, so this line always resets your data:

let store = {};
let allProducts = store.allProducts || [];

There is no shared memory between pages in n8n, so every iteration only contains the current page’s products and overwrites the previous ones. That’s why you always end up seeing only the last page.

The fix is to let each page return its own result and use a Merge node in Append mode after the pagination loop. This way n8n accumulates the output of every page instead of replacing it.

After the Merge, add one final Code node to combine everything into a single array:

const all = $input.all().flatMap(i => i.json.allProducts || []);
return [{ json: { allProducts: all } }];

This collects all pages from the Merge and gives you one complete dataset in the last node.

Isn’t there any global state or global variable where I can temporary hold all the products response. Even the merge node data is replaced inside the loop after every iteration and if I put the merge node after the if statement outside the loop then the false branch only contains 1 item, the other item is in the true branch.