Skip to main content

Hi All,


So I am trying to create a new record in Airtable using google app script. I have been using the API documentation and reading the forum but can’t seem to get it to work. Any help would be much appreciated. Thank you.


Code snippet


var baseKey = 'XXX';
var airtableAPIKey = 'XXX';
var airtableAPIEndpoint = 'https://api.airtable.com/v0/';
var tableName = 'Table 3';

var payload = {
"records": :
{"fields": {
"Name": "Jeff",
"Date": "2020-11-15",
"Status": "Done"
}}
]
};


function AirPost(baseKey, tableName, payload) {

var options = {

method: 'POST',
headers: {
'Authorization ': 'Bearer ' + airtableAPIKey,
'Content-Type ' : 'application/json'
},
payload : JSON.stringify(payload),
muteHttpExceptions : true
};

var response = UrlFetchApp.fetch(airtableAPIEndpoint + baseKey + "/" + encodeURIComponent(tableName), options).getContentText();
return(response);
}

I think you’re really close -


var payload = {
"records": s
{"fields": {
"Name": "Jeff",
"Date": "2020-11-15",
"Status": "Done"
}}
]};

// call the API function...
response = AirPost(baseKey, tableName, payload);
Logger.log(response);

function AirPost(baseKey, tableName, payload) {
...


I think you’re really close -


var payload = {
"records": s
{"fields": {
"Name": "Jeff",
"Date": "2020-11-15",
"Status": "Done"
}}
]};

// call the API function...
response = AirPost(baseKey, tableName, payload);
Logger.log(response);

function AirPost(baseKey, tableName, payload) {
...

Thank you so much for the help. It is working now.


Reply