Split out more than 100 items?

Hi everyone,

I am trying to split out an item which contains more than 2700 sub-items.
When I do it using Item Lists node, it only return the 100 first items as you can see in the screenshot :

Is there a way to return all of the 2700 items in this list ?

Thank your for your precious help :slight_smile:

Workflow :

Hey @PrintEurope,

Welcome to the community :tada:

My first thought here is next to the highlighted total it has Count and Limit which are both set to 100 so to me this looks like it is working as expected and you may need to implement a pagination loop with the API you are using to get the other 2605 records.

1 Like

Hi @Jon, Thank you for your quick reply !
I’ll try this !

You were right !

Here is the answer in the API documentation :

Use the offset parameter to get all orders in a store.
For example, if a store has 452 orders, you would need to call the /orders endpoint 5 times with different offset parameter values:
offset=0 // 0-100 orders
offset=100 // 100-200 orders
offset=200 // 200-300 orders
offset=300 // 300-400 orders
offset=400 // 400-452 orders
As a result, you will get all 452 orders after these 5 consecutive requests.

But how can I make the loop to add 100 to the offset and get all the orders ?
Can you help me with that ? :slight_smile:

Thanks a lot !

Hi @PrintEurope, pagination can be implemented using a loop like so for example:

I don’t have access to your API, but you should be able to adjust the example. I am using the $runIndex here to keep track of how often the loop has been running. Since your API expects an offset rather than a page number you probably want to use {{ $runIndex * 100 }} on the Set node and replace the page query parameter with the offset parameter required by your API. For the IF node you’d need to find a suitable comparison taking your data structure into account.

It should look like this when running:

Recording 2022-11-22 at 17.00.53

If you want to further process your data once the loop has finished, you might also want to take at this workflow which can make life easier: Merge multiple runs into one | n8n workflow template

Give me a shout if need further help with this :)f

Hi @MutedJam and thank your for your reply that helped me a lot for making the loop !

Now I added the Code node and changed “noop” by “items” because it’s what I want to concat.

As you can see, the output is empty.
Am I doing something wrong ?

Thanks again for your help :slight_smile:

Hi @PrintEurope, the code would expect the name of the node, not the field. So, if the node you want to take the data from is called HTTP Request, the code would look like so:

let results = [],
  i = 0;

do {
  try {
    results = results.concat($("HTTP Request").all(0, i));
  } catch (error) {
    return results;
  }
  i++;
} while (true);

After merging the items through the code node you could then use an Item Lists node to split out the items field itself.

The syntax of $("node-name").all(branchIndex?, runIndex?) would be documented here.

Great, that’s working fine !
Thank you for your help :slight_smile:

1 Like

Awesome, really glad to hear that. Thanks so much for confirming!