Hi everyone,
I'm trying to build a flow that would ultimately create purchase records in my Knack database for each Shopify order. Shopify orders support line items and I'd like to create one record for each item.
So here's what I got:
Shopify sample outputs:
Now I'd like to create an array in Flow that looks something like this:
[ { "SKU": "ex1", "Qty": 1, "Price": "$10" }, { "SKU": "ex2", "Qty": 2, "Price": "$20" } ]
And this should help me create 2 records in my database.
I tried using Compose with split() to split the strings into an array, and then Select to map the outputs like this:
Then I ended up with 3 Selects that look like this:
... so this obviously won't help me achieve what I'm after - the end result is an array with 9 "records", each with either SKU, or Qty, or Price field filled in.
If anyone can help me figure out how to split/combine these separate strings into a workable array, I'd very much appreciate it!
Cheers
Hi Alice, apologies for the delay and thank you for your reply. I managed to figure this out with a possibly convoluted set of actions, but here it is in case it helps anyone:
Each item has it's own SKU code, quantity, price, etc. This information is being passed to my flow in string groups like this:
(Text Field 1) SKU: skuCode1,skuCode2,skuCode3... (Text Field 2) Qty: qty1,qty2,qty3... (Text Field 3) Price: price1,price2,price3...
And my end result needs need to be like this:
[ { "SKU": "skuCode1", "Qty": "qty1", "Price": "price1" }, { "SKU": "skuCode2", "Qty": "qty2", "Price": "price2" }, { "SKU": "skuCode3", "Qty": "qty3", "Price": "price3" }
---
Solution:
1. Create a Compose action for the first field (SKU). Compose action:
split(triggerBody()?['SKU'],',')
2. Create an array variable with initial value set to:
outputs('Compose_SKU')
The initial value of array ArraySKU is:
{ skuCode1, skuCode2, skuCode3, ... }
3. Create (1) and (2) for each field that contains details that need to be put in the final array. So e.g. Compose_Qty / Array_Qty, Compose_Price / Array_Price, Compose_Name / Array_Name, etc.
4. Create an integer variable which will be used to select a specific element from the arrays. Initial value set to 0.
5. Create an "Apply to each" loop for the output of Compose_SKU action (because that's effectively my total number of items) and write the array for fields as follows:
{ "SKU": =if(equals(length(variables('ArraySKU')),0),'',variables('ArraySKU')[variables('CounterArray')]), "Qty": =if(equals(length(variables('ArrayQty')),0),'',variables('ArrayQty')[variables('CounterArray')]), "Price": =if(equals(length(variables('ArrayPrice')),0),'',variables('ArrayPrice')[variables('CounterArray')]), ... }
i.e. if ArrayXYZ is empty, return nothing, else return nth item of the array, where n is determined by the counter variable from step 4.
6. At the end of the loop, increment Counter variable.
(Note: the HTTP in my example could also be replaced with "append to array" but it would've been an unnecessary step for my flow.)
---
Final flow looks like this:
Cheers!
Hi @Ines,
You said that you use Compose with split() to split the strings into an array, could you please share more details about the strings?
And do you want to Join multiple strings to array as below:
[ { "SKU": "ex1", "Qty": 1, "Price": "$10" }, { "SKU": "ex2", "Qty": 2, "Price": "$20" } ]
Please share the strings with us so we woyuld try to provide a proper workaround for you.
Best regards,
Alice
Tomac
986
Moderator
stampcoin
699
Super User 2025 Season 2
Riyaz_riz11
577
Super User 2025 Season 2