Help

Can't find offset value in API while using Node.js/Express

1335 1
cancel
Showing results for 
Search instead for 
Did you mean: 
Blake_Eskin
5 - Automation Enthusiast
5 - Automation Enthusiast

I am building a web application for my students using Node.js/Express that displays information from an Airtable base.  Instead of embedding a table of news stories, I want to pull several fields from the table and insert them into the DOM so I can design the display of information. 

I've been able to send 3, 5, 10 stories to the console, but when I try to send a second story to display on a web page, I keep running into this error: 

 

TypeError: Cannot read properties of undefined (reading 'offset')

 

which points to part of airtable.js that compares result.offset with params.offset. 

I've tried to find an offset in the json but I don't see the key or values beginning with itr.

I tried to call record.offset but it is undefined.

Several community posts about offset explain how to find more than the maximum 100 records, but I'm getting stuck on the second record.

I found Offset property missing in API response as an open issue on Github from 2021, so maybe there's no way to do this, but I'm hopeful there is a way forward.

This is the relevant part of my Express script:

 

 

app.get('/api/stories', (req, res) => {
    base(table).select({
        maxRecords: 10,
        view: view
    }).eachPage(function page(records, fetchNextPage) {
records.forEach(function(record) {
          console.log('Retrieved', record.get('Happened'), record.get('Created By').name);
          // TODO: something is breaking here the second time through. Offset is undefined and it matters only the second time. 
          res.json({
            'Happened': record.get('Happened'),
            'Created By': record.get('Created By').name,
}); 
        });
fetchNextPage();        
}, function done(err) {
        if (err) { console.error(err); return; }
    });
});

 

 Thanks for your help!

1 Reply 1

Hmm, I don't think the JavaScript library comes with 'offset' actually.  I looked at the interactive documentation for my bases (https://airtable.com/developers/web/api/introduction and then clicking into the base) and I can't seem to find an 'offset' value or an ability to select which page we want to grab

The documentation for the direct API calls does have an offset though, so as a last resort you could use that I suppose? https://airtable.com/developers/web/api/list-records

Seems weird and I feel like I'm missing something!