Nov 14, 2020 02:53 PM
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);
}
Solved! Go to Solution.
Nov 14, 2020 03:17 PM
I think you’re really close -
var payload = {
"records": [
{"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) {
...
Nov 14, 2020 03:17 PM
I think you’re really close -
var payload = {
"records": [
{"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) {
...
Nov 15, 2020 03:53 AM
Thank you so much for the help. It is working now.