Stuck on how to split a large array into smaller arrays

I’m currently integrating Xero and Shopify. The intention is to run a daily inventory sync, that queries Xero and then updates Shopify with the current inventory levels.

One problem I’ve encountered is Xero wants to return ALL the inventory items back to me in a single API call, which is over 6000 items in a single array. Make is parsing it, which is fine. However, I need to break this into smaller groups of 250 items per group. Then I can use the Shopify GraphQL to send only 24 API calls to update all the inventory for all products.

I’ve tried a lot of ways to approach it but I cannot seem to find a way to slice the array, then be able to iterate through each slice and feed into a Shopify module.

Hi @Anonymax,

It might require a few iterations on your end to set this up, but based on the problem that you have specified, what you can do is,

  1. Use Array Aggregator to Aggregrate all the 6000 items that you get from Xero
  2. Use a Repeater Module, that will start with 0 and will go to floor(length(items)/24)
  3. Now After the aggregator what you can do is either setup a Set a Variable Module or directly use it in your target module that will slice the array with formula,

{{slice(3.array; (4.i * 24) + 1; (4.i + 1) * 24)}}

Screenshot from 2023-05-01 17-06-24

Just give a try and see how it goes.

1 Like

I misread, so you might need to use 250 instead of 24.

Worked, this was my final Scenario. Your suggested Repeated/Split worked well, I just had to juggle the array a bit either side. Thank you!

1 Like