Help

Re: Creating a post request in Google App Script

Solved
Jump to Solution
2441 0
cancel
Showing results for 
Search instead for 
Did you mean: 
Simon_Gallagher
5 - Automation Enthusiast
5 - Automation Enthusiast

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
Bill_French
17 - Neptune
17 - Neptune

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
Bill_French
17 - Neptune
17 - Neptune

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.