Comment on page

Export Airtable to Google Sheets

Update a Google Sheet with Airtable data on a schedule
Google sheets allows you to easily create automations in your Google Sheet using Google App Script. We are going to use it to create a function that will update your GSheet with your latest Airtable data. The great thing about this function is that it can be scheduled to run at an interval of your choosing.

Step 1

Open your Google sheet and click 'Extentions'.

Step 2

Under Extensions, click App Script.

Step 3

In your file, paste the following code
function csvGetter() {
var url = "";
// Fetch the CSV file
var response = UrlFetchApp.fetch(url);
// Get the contents of the file as a string
var csvString = response.getContentText();
// Convert the CSV string to a 2D array
var csvData = Utilities.parseCsv(csvString);
// Get the active sheet
var sheet = SpreadsheetApp.getActiveSheet();
// Clear the existing data in the sheet
// Write the data from the CSV file to the sheet
sheet.getRange(1, 1, csvData.length, csvData[0].length).setValues(csvData);

Step 4

Saving the file, you can now run the function called csvGetter. (You may need to give this script permission to access the sheet. I explain this in the video above.)

Step 5

Once you have run the function ... Congratulations!
- your gsheet will now be full of your Airtable data.
Now lets setup a schedule. Back in the Apps Script screen, click Triggers (the alarm clock icon)
Click Add Trigger
Under trigger settings, click 'Time Driven' - this allows you to customise how often the trigger is run.
These settings will mean that the google sheet will update every hour
Once you press save, your Trigger is live
. You can see its working by waiting for a 'Last Run' timestamp to appear.
And now your Google Sheet is updating automatically from Airtable.

Optional Step 6:

Add ?email_me=true to the end of your URL to recieve an email notification of your scheduled backup. You can even add a label by appending &email_tag=<your_tag>. Check out the example:
In this example, I'd like my email to show me I have backed up Airtable with google sheets
With email_me set to true, you will get an email like this (limited 1 per day)

Script enhancements (more coming soon):

Update more than one sheet, using multiple export URLS:

function csvGetter() {
var sheetInfo = [
{ url: "", sheetName: "Sheet1" },
{ url: "", sheetName: "Sheet2" },
// add more if needed
// Loop through the array and update each sheet
for (var i = 0; i < sheetInfo.length; i++) {
var info = sheetInfo[i];
updateSheetFromCSV(info.url, info.sheetName);
function updateSheetFromCSV(url, sheetName) {
var response = UrlFetchApp.fetch(url);
var csvString = response.getContentText();
var csvData = Utilities.parseCsv(csvString);
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
var sheet = spreadsheet.getSheetByName(sheetName);
if (!sheet) {
sheet = spreadsheet.insertSheet(sheetName);
} else {
sheet.getRange(1, 1, csvData.length, csvData[0].length).setValues(csvData);