Hi all, so I’m creating this workflow to search image on the internet, validate the image link, and then return one image link with the best quality and size.
Specifically:
- After searching for the images using SerpAPI on an HTTP Request, I got 100 search results
- Then I use the Split Out node to only proceed with the image results
- Then I use Code to slice the data into 10, and then loop through the 10 image results
- Inside the Loop, I fetch headers via HTTP and filter out invalid images (broken link) via an IF node
- Then tag each image with size, resolution, quality, etc, using Code, and all 10 data points will be combined into one array. ((this is where it went wrong))
- On the next node, filter and sort the array based on the quality and sizes, and return one link that passed the criteria
Now I want to combine all 10 items that have been validated and tagged into one single item, like:
{
"tagged_images": [ {...}, {...}, {...} ]
}
But, instead, I get 10 arrays with one item
I’ve tried everything:
- Code node (Run Once for All Items) using .map() or .push()
- Merge node (Append, Combine, and Position)
- Aggregate node (Merge Lists or Individual Fields)
No matter what, I still get 10 separate items instead of one item with a nested array.
My constraint: I need to combine items after image validation, but still preserve metadata from the original loop (like headers from HTTP).
Can anyone suggest the cleanest way to:
- Wait until the loop is done,
- Then gather the resulting items into one array, inside one item?
Here is the code:
I really appreciate any help you can provide. Thanks