Merging many-to-many items

I have an n8n workflow where I first fetch a list of Trello cards, and then for each card I fetch its attachments.

What is the best way to structure the workflow so that, in the end, I get a combined array like this?

[ 
    {
        "card": { ... }, 
        "attachments": [ ... ] 
    },
    {
        "card": { ... },
        "attachments": [ ... ]
    }
]

Right now, after iterating over the cards and fetching attachments, I’m not sure what the correct pattern is in n8n to merge the data back together.

Should I use Merge nodes, Item Lists, Code node, or some other approach?

I guess merge node could do the job. if you combine them in this fashion and combine by either matching field or position.

Thanks for the suggestion.

I’m not sure how the Merge node would help in this case, though.

The problem is that attachments don’t contain any field that can be used to reliably link them back to the corresponding card (no cardId or similar reference in the attachment data).

For example, if one card has 2 attachments, the workflow produces something like:

[{ ...card }, { ...attachment1 }, { ...attachment2 }]

Using Merge by position doesn’t seem to work here because it would incorrectly combine unrelated items and could result in data loss or overwriting attachments, depending on how the pairing is done.

And Merge by matching field also doesn’t apply since there is no shared key between the card and its attachments.

Because of that, I’m not sure how the Merge node could correctly reconstruct a structure like:

[
  { card, attachments: [...] },
  ...
]

Ohk, had not used trello card node , so did not knew about multiple outputs for one. 1 solution can be to use loop and get data of 1 trello card at a time so that we can map it or save the data for 1 card with it’s card id. If you want to keep record, you can map and store them in a google sheet ( simplest way ). You can also set to see output for different loop iterations in set fields node.

Looks like I found a working solution: