I'm trying to take data form a get requet to Airtable and put the records into an array called aTotalRecords. I cannot get this function to return the data. I've tried a bunch of combinations of async/await and .then(). I know this subject has been covered by answers like this one and I've read a couple posts like this. But, I cannot get it to work. What am I missing.
import Airtable from 'airtable';
import oConfig from './configFile.js';
function getAirtableData(){
var base = new Airtable({apiKey: oConfig.oConfig.airtableAPIKey}).base(oConfig.oConfig.airtableBaseKey);
var aTotalRecords = [];
base('Polygon Transactions').select({
maxRecords: 500
}).eachPage(function page(records, fetchNextPage) {
records.forEach(function(record) {
aTotalRecords.push(record.get('tx_hash'));
});
fetchNextPage();
}, function done(err) {
if (err) { console.error(err); return; }
});
// return Promise
// console.log(aTotalRecords)
// return await Promise.resolve(aTotalRecords)
return aTotalRecords
};
// getAirtableData().then(console.log);
async function allAirtableRecords() {
return getAirtableData();
};
allAirtableRecords().then(console.log);