Copy all records to Google Sheets with Apps Script

A Google Apps Script that pages through every record of a table with the REST API, respects rate limits, and refreshes a sheet on a schedule.

  • Verified Nov 17, 2026
  • Classic builder

On this page
  1. Before you start
  2. Set it up
  3. How the script uses the API
  4. Run it on a schedule
  5. Common problems

This Google Apps Script copies every record of one Tadabase table into a Google Sheet, one row per record. It reads the table through the REST API one page at a time, waits when the API asks it to slow down, and can run on a schedule so the sheet stays up to date.

Before you start #

Set it up #

  1. Open Apps Script Create a Google Sheet, then choose Extensions > Apps Script.
  2. Paste the script Delete the sample code in the editor, paste the script below and save the project.
  3. Store your keys Open Project Settings (the gear icon) and, under Script Properties, add four properties: TADABASE_APP_ID, TADABASE_API_KEY, TADABASE_API_SECRET and TADABASE_TABLE_ID. Keeping the keys here keeps them out of the code.
  4. Run it once Back in the editor, select copyAllRecords and click Run. Google asks you to authorize the script the first time. When it finishes, the sheet has a tab named Tadabase records with a header row and one row per record.
javascript
// Copies every record of one Tadabase table into the "Tadabase records" tab.
// Set these Script Properties first (Project Settings > Script Properties):
// TADABASE_APP_ID, TADABASE_API_KEY, TADABASE_API_SECRET, TADABASE_TABLE_ID

var SHEET_NAME = 'Tadabase records';
var PAGE_SIZE = 100;   // records per API call
var MAX_RETRIES = 5;   // how often to retry a call the API refused with 429

function onOpen() {
  SpreadsheetApp.getUi()
    .createMenu('Tadabase')
    .addItem('Copy all records', 'copyAllRecords')
    .addToUi();
}

function getSettings_() {
  var props = PropertiesService.getScriptProperties();
  var settings = {
    TADABASE_APP_ID: props.getProperty('TADABASE_APP_ID'),
    TADABASE_API_KEY: props.getProperty('TADABASE_API_KEY'),
    TADABASE_API_SECRET: props.getProperty('TADABASE_API_SECRET'),
    TADABASE_TABLE_ID: props.getProperty('TADABASE_TABLE_ID')
  };
  Object.keys(settings).forEach(function (name) {
    if (!settings[name]) throw new Error('Add the script property ' + name);
  });
  return settings;
}

// GETs a path under the table. Waits and retries when the API answers 429.
function callApi_(settings, path) {
  var url = 'https://api.tadabase.io/api/v1/data-tables/' + settings.TADABASE_TABLE_ID + path;
  for (var attempt = 0; attempt <= MAX_RETRIES; attempt++) {
    var response = UrlFetchApp.fetch(url, {
      method: 'get',
      headers: {
        'X-Tadabase-App-Id': settings.TADABASE_APP_ID,
        'X-Tadabase-App-Key': settings.TADABASE_API_KEY,
        'X-Tadabase-App-Secret': settings.TADABASE_API_SECRET
      },
      muteHttpExceptions: true
    });
    var code = response.getResponseCode();
    if (code === 429) {
      var headers = response.getHeaders();
      var wait = Number(headers['Retry-After'] || headers['retry-after']) || 60;
      Utilities.sleep(Math.min(wait, 60) * 1000);
      continue;
    }
    var body = JSON.parse(response.getContentText());
    if (code !== 200 || body.type !== 'success') {
      throw new Error('Tadabase API error ' + code + ': ' + (body.msg || response.getContentText()));
    }
    return body;
  }
  throw new Error('The API is still rate limiting after ' + MAX_RETRIES + ' retries.');
}

// Turns a value with several parts (a name, an address, a list, a file) into text.
function toText_(value) {
  if (value === null || value === undefined) return '';
  if (Array.isArray(value)) return value.map(toText_).filter(String).join(', ');
  if (typeof value === 'object') {
    if (value.url) return value.url;
    return Object.keys(value).map(function (key) { return toText_(value[key]); }).filter(String).join(' ');
  }
  return value;
}

function cellValue_(record, field) {
  // A connection field also comes back as <slug>_val: the connected records' display values.
  var connected = record[field.slug + '_val'];
  if (Array.isArray(connected)) {
    return connected.map(function (item) { return item.val; }).join(', ');
  }
  return toText_(record[field.slug]);
}

function copyAllRecords() {
  var settings = getSettings_();
  var fields = callApi_(settings, '/fields').fields;
  var rows = [['Record ID'].concat(fields.map(function (field) { return field.name; }))];

  var page = 1;
  var totalPages = 1;
  do {
    var result = callApi_(settings, '/records?limit=' + PAGE_SIZE + '&page=' + page);
    result.items.forEach(function (record) {
      rows.push([record.id].concat(fields.map(function (field) { return cellValue_(record, field); })));
    });
    totalPages = result.total_pages;
    page++;
    Utilities.sleep(250); // a short pause between pages keeps large tables under the rate limit
  } while (page <= totalPages);

  var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = spreadsheet.getSheetByName(SHEET_NAME) || spreadsheet.insertSheet(SHEET_NAME);
  sheet.clearContents();
  sheet.getRange(1, 1, rows.length, rows[0].length).setValues(rows);
}

How the script uses the API #

CallWhat the script uses
GET /api/v1/data-tables/{tableId}/fieldsfields: each field's name (the column header) and slug (the key in each record).
GET /api/v1/data-tables/{tableId}/records?limit=100&page=Nitems (the records on page N) and total_pages. Records come back in ID order, so every page picks up where the last one ended.
  • Each call sends the X-Tadabase-App-Id, X-Tadabase-App-Key and X-Tadabase-App-Secret headers.
  • The script asks for 100 records per call. A larger limit is lowered to the server's maximum, so a bigger number does not save calls.
  • When the API refuses a call with status 429, it says in the Retry-After header how many seconds to wait. The script waits that long (at most a minute) and tries again. See Rate limiting.
  • Each run replaces the tab's contents. Fields with several parts, such as Name and Address, are joined into one cell, and connection fields show the connected records' display values.

Run it on a schedule #

  1. Open Triggers In the Apps Script editor, click Triggers (the clock icon) and then Add Trigger.
  2. Choose the function Choose copyAllRecords as the function to run.
  3. Choose how often Set the event source to Time-driven and pick an interval, for example every hour or every day. Save.

Each scheduled run makes one API call per page of records, and those calls count toward your app's API limits. Pick the longest interval that still keeps the sheet fresh enough.

Common problems #

What you seeWhat to do
Add the script property ...A Script Property is missing or misspelled. Check the four names under Project Settings.
Tadabase API error 412The key is not allowed to read records. Turn on Allow Reads for it.
Tadabase API error 200: Data Table not foundCheck TADABASE_TABLE_ID. It must be a table of the app the key belongs to.
The script stops before it finishesGoogle limits how long one run can take. For a very large table, export it to CSV instead and import the file: see Export records to CSV.

Was this page helpful?

Something wrong or missing on this page? Tell us.