Help

Upcoming database upgrades. Airtable functionality will be reduced for ~15 minutes at 06:00 UTC on Feb. 4 / 10:00 pm PT on Feb. 3. Learn more here

Creating a post request in Google App Script

Topic Labels: API
Solved
Jump to Solution
1170 2
cancel
Showing results for 
Search instead for 
Did you mean: 

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);
}
1 Solution

Accepted Solutions

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) {
  ...

See Solution in Thread

2 Replies 2

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) {
  ...

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