Last active
February 11, 2021 13:15
-
-
Save gtalarico/e2114666e7fc38d5c144f7c514da687a to your computer and use it in GitHub Desktop.
Airtable Netlify Lambda Function Setup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// lambda/airtable.js | |
const Airtable = require('airtable') | |
Airtable.configure({ | |
endpointUrl: 'https://api.airtable.com', | |
apiKey: process.env.AIRTABLE_KEY | |
}) | |
const base = Airtable.base('appNtnZ99fkL1cByn') | |
exports.handler = function(event, context, callback) { | |
const allRecords = [] | |
base('entries') | |
.select({ | |
maxRecords: 100, | |
view: 'all' | |
}) | |
.eachPage( | |
function page(records, fetchNextPage) { | |
records.forEach(function(record) { | |
allRecords.push(record) | |
}) | |
fetchNextPage() | |
}, | |
function done(err) { | |
if (err) { | |
callback(err) | |
} else { | |
const body = JSON.stringify({ records: allRecords }) | |
const response = { | |
statusCode: 200, | |
body: body, | |
headers: { | |
'content-type': 'application/json', | |
'cache-control': 'Cache-Control: max-age=300, public' | |
} | |
} | |
callback(null, response) | |
} | |
} | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment