Looping over airtable row then attachments

So I’m trying to get all the rows in airtable that have attachments and then process each row. A row may have multiple attachments and I need to process each attachment separately but I can’t seem to get n8n to do individual attachments. Here is my setup.

In my test case I have 2 Airtable rows, first row has 2 attachments, 2nd row has 1 attachment. Here is what I see after the run

Loop Over Items seems to pass 2 items to Code instead of 3

Similarly if I try to loop over files in a form i can’t seem to do it and it just batches it and treats it as one row…

Solution for Looping Over Airtable Attachments

  1. Get Airtable Records

    • Use the Airtable node to fetch all rows with attachments
    • Set “Download Attachments” to true
  2. Process Rows with Attachments (Function Node)

// Flatten rows into individual attachment items
const newItems = [];

for (const row of items) {
  if (row.json.attachments && row.json.attachments.length > 0) {
    for (const attachment of row.json.attachments) {
      newItems.push({
        json: {
          ...row.json,
          single_attachment: attachment,
          // Keep other row data as needed
        },
        binary: {
          attachment_data: row.binary[attachment.filename]
        }
      });
    }
  }
}

return newItems;
  1. Loop Node Configuration
    • Add an “Iterator” node after the Function node
    • Set mode to “Individual Items”
    • This will now process each attachment separately

Hi @Martin_Kaufman

This is because the Loop input items is 2 not 3