How to Unbundle data from Airtable using Function?

Hi - I am new to N8N so I may be missing something obvious here and I appreciate your patience.

I have Airtable hooked up to a Function. Inside that Function I need to unbundle the data.
Screen Shot 2021-05-07 at 1.48.31 PM

Inside the Function node, when I simply execute return items; the data looks like this
example data below:

[
    {
    "records": [
        {
        "id": "r1234567890",
        "fields": {
            "Company Name": "John Doe Company",
            "Type": "e-commerce, retail, manufacturing",
        },
        "createdTime": "2021-05-01T15:00:00.000Z"
        },
        {
        "id": "r0987654321",
        "fields": {
            "Company Name": "Jill Example Company",
            "Type": "cosmetics, e-commerce",
        },
        "createdTime": "2021-05-01T15:00:00.000Z"
        }
    ],
    "offset": "2092390ksdk0923ks43"
    }
]

I see “Items: 1”, which I expect to see. My task now is to unbundle it and retrieve the individual objects inside. After watching this youtube video, reading the documentation and through trial and error, I cannot figure out how to unbundle this data.

I tried iterating over items inside “records” but I always end up just seeing Items:1 instead of Items:100, for instance.

return items[0].json.records.map(r => ({ json: r }));

Your input has the shape Array<{ json: { records: Array<Record> }}> so you need to first access the internal array, and then iterate over those items to produce an output shaped Array<{ json: Record }>.

This docs page might be useful.

3 Likes

Ah, yes! Makes a lot of sense. Thanks so much