Google Apps Script — AirTable API

Urvah Shabbir
3 min readNov 7, 2019

--

Just putting it out there for some one who forgets syntax of RESTful API call in Google Apps Script.EVERY.SINGLE.TIME. This one is for AirTable API.

STEP # 1 — GET THE AIRTABLE API KEY

Go to https://airtable.com/account, (assuming you are logged in your account) and copy API key from the page.

STEP # 2 — SELECT THE AIRTABLE BASE (DATABASE)

Go to https://airtable.com/api and select the base to view API documentation. For example, if I click on “Project Tracker” I am redirected to this url: `https://airtable.com/apphp10uEyLZkBvpM/api/docs#curl/introduction`. From this url, the id of this base is apphp10uEyLZkBvpM . Note this down.

STEP # 3 — CHOOSE BASE TABLE

I am choosing Design Projects table for this API request.

STEP # 4 — SETUP APPS SCRIPT

Go to https://script.google.com and click New Project on top left. Copy+Paste the following code:

function apiCall(){

var API_KEY = 'ENTER YOUR API KEY HERE';
var root = 'https://api.airtable.com/v0';

var baseId = 'ENTER YOUR BASE ID HERE';
var tableName = encodeURIComponent('Design Projects');

var endpoint = '/' + baseId + '/' + tableName;

var params = {
'method': 'GET',
'muteHttpExceptions': true,
'headers': {
'Authorization': 'Bearer ' + API_KEY
}
};

var response = UrlFetchApp.fetch(root + endpoint, params);
var data = response.getContentText();
var json = JSON.parse(data);
Logger.log(json);
return (json);
}

Press the Run button in the toolbar, and Viola! You will have your JSON output from airtable > base > table to play around with. It would look something like this:

{"records": [{"id": "rec3m3DIIKg2YvaMr","fields": {"Name": "MIT Media Lab Logo","Project Photos": [{"id": "attXnUsvmBV4vsUya","url": "https://dl.airtable.com/1ITT2U0NT6CxxlO08QwU_07_MITML_ML_logo_white_on_black.jpg","filename": "07_MITML_ML_logo_white_on_black.jpg","size": 26678,"type": "image/jpeg","thumbnails": {"small": {"url": "https://dl.airtable.com/is7SbbKpTSW8LiIuZQct_small_07_MITML_ML_logo_white_on_black.jpg","width": 54,"height": 36},"large": {"url": "https://dl.airtable.com/MCwXEB0lRMyw3LPEUkqd_large_07_MITML_ML_logo_white_on_black.jpg","width": 256,"height": 171}}},{"id": "attgApDDpssXLb21Q","url": "https://dl.airtable.com/hLB8ixxcQNGljg4RACFH_06_MITML_ML_logo_black_on_white.jpg","filename": "06_MITML_ML_logo_black_on_white.jpg","size": 26683,"type": "image/jpeg","thumbnails": {"small": {"url": "https://dl.airtable.com/NPS1nwqDTpg2gEz1AhWv_small_06_MITML_ML_logo_black_on_white.jpg","width": 54,"height": 36},"large": {"url": "https://dl.airtable.com/OaQnEbOdR4qvT4T0uCql_large_06_MITML_ML_logo_black_on_white.jpg","width": 256,"height": 171}}}],"Client": ["recTcoqYbUcSXQPQ3"],"Category": "Brand Identity","Complete": true,"Project Lead": {"id": "usrlyM7zyPdGhDIKS","email": "kat+emilypilloton@airtable.com","name": "Emily Pilloton"},"Project Team": [{"id": "usrfJQIOYUIFLuTgc","email": "kat+anishkaclarke@airtable.com","name": "Anishka Clarke"}],"Due date": "2017-10-31","Kickoff date": "2017-10-17"},"createdTime": "2015-02-10T20:59:28.000Z"},

NOTES:

  • If you are running the script for the first time a pop up will open. Choose your email in popup # 1 > Select ‘Advance’ and then ‘Go to your-script-name-here’ in popup # 2 > Select ‘Allow’ in popup # 3
  • More information on what base id to use and table name to use can be found on https://airtable.com/api
  • More quick google app script code snippets can be found at https://github.com/urwa/GoogleAppsScript

--

--