Skip to content
How to sync data between Coda docs (and Google Sheets) using Google Apps Script

Original Coda -> Coda Script

Original script one-way sync script from
CodaAPI.authenticate('abcd1234-efgh-5678-ijkl-1234mnop5678'); // Replace with your token.

doc: 'TO UPDATE',
table: 'Source Table',
// Add more as needed.
doc: 'TO UPDATE',
table: 'Target Table',

/** Run me! */
function oneWaySync() {
for each (var source in SOURCE_TABLES) { //If you are using the V8 runtime delete "each" from this line
syncSpecificTable(source, TARGET_TABLE);

// TODO: handle pagination for syncing source tables with >500 items.
function syncSpecificTable(source, target) {
// Get info on the source and target tables.
var sourceTable = CodaAPI.getTable(source.doc, source.table);
var targetTable = CodaAPI.getTable(target.doc, target.table);
Logger.log('::::: Syncing "%s" => "%s"...',,;

// Find which columns we have to sync.
var sourceColumns = CodaAPI.listColumns(source.doc, source.table) { return; });
var targetColumns = CodaAPI.listColumns(target.doc, target.table) { return; });
var commonColumns = intersection(sourceColumns, targetColumns);
Logger.log('Syncing columns: %s', commonColumns.join(', '));
// Pull down all the rows in the source table.
var sourceRows = CodaAPI.listRows(source.doc, source.table, {limit: 500, useColumnNames: true}).items;
Logger.log('Source table has %s rows', sourceRows.length);

// Upsert all rows in the source table into the target table.
var upsertBodyRows = {
var cells = {
return {
column: colName,
value: row.values[colName],
// Add a URL to the source row in the target, table, which will also be used as the upsert key.
cells.push({column: TARGET_TABLE_SOURCE_ROW_COLUMN, value: row.browserLink})
return {cells: cells};
CodaAPI.upsertRows(target.doc, target.table, {rows: upsertBodyRows, keyColumns: [TARGET_TABLE_SOURCE_ROW_COLUMN]});
Logger.log('Updated %s!',;

function intersection(a, b) {
var result = [];
for each (var x in a) { //If you are using the V8 runtime delete "each" from this line
if (b.indexOf(x) !== -1) {
return result;
Want to print your doc?
This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (
) instead.