How to fetch multiple field values using Airtable API

I’m working with an Airtable database and I can successfully pull records using the API. My current setup lets me get data from one field called “Location” but I need to grab values from additional fields too.

Right now I’m using console.log('Data found: ', record.get('Location')); to display the Location field. I want to also show data from a field named “Size” in the same output. I attempted console.log('Data found: ', record.get('Location', 'Size')); but this approach failed.

My current code looks like this:

// Fetch 3 entries from Storage table
database('Storage').select({
    maxRecords: 3,
    view: "Main view"
}).eachPage(function processPage(entries, getNextPage) {
    entries.forEach(function(entry) {
        console.log('Data found: ', entry.get('Location'));
    });
    
    getNextPage();
    
}, function finished(error) {
    if (error) { console.error(error); return; }
});

Current result:

Data found 170000118

Data found 170000119

Data found 170000120

What’s the correct way to retrieve and display multiple field values from each record?

You need to call record.get() separately for each field - it only takes one field name at a time.

Here’s the fix:

database('Storage').select({
    maxRecords: 3,
    view: "Main view"
}).eachPage(function processPage(entries, getNextPage) {
    entries.forEach(function(entry) {
        const location = entry.get('Location');
        const size = entry.get('Size');
        console.log('Data found: Location =', location, ', Size =', size);
    });
    
    getNextPage();
    
}, function finished(error) {
    if (error) { console.error(error); return; }
});

I’ve used Airtable’s API for years - this is how everyone does it. Want cleaner output? Store the values in an object:

entries.forEach(function(entry) {
    const data = {
        location: entry.get('Location'),
        size: entry.get('Size')
    };
    console.log('Data found:', data);
});

This logs both field values together.

Just use template literals - way easier to read. Something like console.log('Data found: ${entry.get('Location')} - ${entry.get('Size')}'); works perfectly and keeps things simple. Don’t bother with extra variables unless you’re doing something more complex with the data later.

If you’re cool with ES6, destructuring assignment works great here. You can grab multiple fields at once and format however you want:

entries.forEach(function(entry) {
    const {Location: location, Size: size} = entry.fields;
    console.log(`Data found: ${location} | Size: ${size}`);
});

I found this when I had a project pulling dozens of fields from each record. entry.fields gets you straight to the raw data without all those get() calls. Just watch out - field names have to match Airtable exactly since it’s case-sensitive. Way cleaner when you need lots of fields, and the code’s easier to read.

This topic was automatically closed 4 days after the last reply. New replies are no longer allowed.