Undefined Data (After Loop)

Hey,

Hope everyone is well, this might be super obviously but I am trying to get data from a API call earlier in a workflow and use it for a subsequent call (to shopify).

There is a loop that calls the product of each item but I am getting undefined. I assuming it is because I can’t access the data before the loop after the loop is aggregated.

What is the best way to deal with this scenario

1 Like

1) Enrich Items Before You Loop

  1. Set Node (just before your loop):
    Use a “Set” node to merge or copy the key fields from your initial API response into each item. For example, if your upstream call returns { storeId, location, … } and you’re about to split out items via SplitInBatches or SplitInItems, add those fields on every item first:
    storeId: {{$json["storeId"]}}  
    location: {{$json["location"]}}  
    product: {{$json["product"]}}  
    
  2. Loop (SplitInBatches or SplitInItems):
    Now each batch/item carries along storeId (and any other metadata), so when you call Shopify you can use {{$json["storeId"]}} without hitting “undefined.”

2) Merge Back After the Loop

  1. Store Original Data:
    Keep your initial API node in scope by not overwriting it.
  2. Split and Process:
    Use SplitInBatches (or a custom loop) to call Shopify for each product.
  3. Merge Node (mode: “Pass Through” + “Keep Key Matches”):
    After you finish the per-item calls, link your loop output and the original API node into a Merge node.
    • Left input = loop results
    • Right input = original API response
    • Mode = “Pass Through” (so loop items stay first)
    • Match By = a common key (for instance, productId)
      This re-attaches the original fields back onto each processed item.
2 Likes

thanks, really interesting indeed.

I have used a first() to pull this data, but its definitely something of interest that i am going to go back and work on.

Using first() is a good quick fix for now especially if the data is static. Enriching items before the loop or merging afterward will give you more flexibility for scaling and handling dynamic data. Happy to help :slightly_smiling_face:

Hi ,
Did that step solve your issue? If it did, can you mark it as correct so others can see the answer?
Best,

@masoom - Yeah definitely agree. The data in the process is quiet static (as its effectively an shopify graphQL call for a specific order.

What you have written above, is def something to consider on more complex flows where it is less static. I come from nodejs land, so normally i would hardcode this logic so getting to ropes a little bit.

I don’t have the option to?

Absolutely that makes total sense.

option for ?

the option to accept the as solution… maybe im too much of a noob