Help

How to export data using appscripts (google sheets) to airtable field type "link to another record"

443 0
cancel
Showing results for 
Search instead for 
Did you mean: 
mipos
4 - Data Explorer
4 - Data Explorer
function blabla()
{
  // Replace the placeholders below with your own API keys and table information
  var airtableApiKey = '-';
  var airtableBaseId = '-';
  var airtableTableName = '';
  
  // Get the active sheet and the range of cells containing your data
  var sheet = SpreadsheetApp.getActiveSheet();
  console.log(sheet.getName());
 
  var dataRange = sheet.getRange(3,1,sheet.getLastRow(),5);
  
  // Get the values in the range as a 2D array
  var data = dataRange.getValues();
  
  var apiUrl = 'https://api.airtable.com/v0/' + airtableBaseId + '/' + airtableTableName;
  var headers = {
    'Authorization''Bearer ' + airtableApiKey ,
    'Content-Type''application/json'
  };

  // Loop through the data in Google Sheets and send it to Airtable
  for (var i = 0i < data.lengthi++) 
  {
      var rowData = data[i];
      var fields = 
      {
          'Rack': rowData[0],  <-- THIS FIELD TYPE is "link to another record"
          'Line #'rowData[1],
         'SKU': rowData[2], <-- THIS FIELD TYPE is "link to another record"
          'Stocklist Notes'rowData[3],
          'Stocklist Desc'rowData[4]
      }
      var options = 
      {
          'method''post',
          'headers'headers,
          'payload'JSON.stringify({fieldsfields})
      };

      // Send the data to Airtable
      UrlFetchApp.fetch(apiUrloptions);   
  }
}

// it works fine for the field that is not field type "link to another record"  anyone know how to solve this problem ? 

      
0 Replies 0