Auto CSV Import

Hey Coda Community, this is Seth from Greylock. We use Coda for a number of things, and I’m trying to increase automation. We have a regular CSV export of multiple files that we do from a web service, and we’d like to pull that information directly into a table in a Coda doc. Copy and paste is OK, but we want to make it easier and also allow for upserting. We don’t use the API for the web service, so we can’t just route the data in directly. Does anyone have a script to handle CSV to Coda upserting? Thanks!

5 Likes

Hey Seth, Ben here from Coda.

This is a pretty common workflow, so I’m glad you asked. Coda has a native CSV import tool and also does well when CSV data is pasted in directly, but a CSV import using a script would be able to handle row redundancy and upsert on existing data.

Google has a great tool to create scripts to connect different services online. I wrote a script here that would handle importing a CSV saved in Google Drive to a Coda doc: https://script.google.com/d/1c-kUejkfLiCIHTj30uiXW_Yl5zefcQkqDGTl-mzGvYZYbPYiFkBPRG4u/edit?usp=sharing

One thing to note is that Google Script relies on the source file being saved on the internet, so for importing CSVs it’s probably easiest to use Google Drive. Drive also means we can utilize Google’s utility library.

You’ll need a few pieces of info to do this, but it’s super easy:

  1. Coda doc ID
  2. Your Coda API key
  3. Google drive folder ID
  4. Target table name
  5. Columns to upsert on

After that, the script handles all the heavy lifting. The script will handle an unlimited number of files in the source folder, but it’ll get slower as that number increases.

To use the script, just make a copy of the script and add your information from 1-5 above.

Coda Community - let me know if you’re doing any interesting workflows that involve automation across disparate online services!

21 Likes

Hi There!

I get an "SyntaxError: Unexpected identifier (line 57, file “Code.gs” when running your script. Has something changed in Google App Scripts that would cause this? I am not an AppScript person myself.

EDIT: I was able to alter the “for” loop to fix the error:

// OLD
for each (var row in data) {
// NEW
data.forEach(function(row){

Lloyd

1 Like