Thanks for the catch @Christiaan_Huizer, it looks like NASA changed the API since this guide was created. I updated the guide to include the proper link and updated the scripts. Here are the following changes that should be made to the script:
The google sync sometimes overwrite the coda table column type, e.g. a date field from Google shows as List. Any suggestions or formatting to be done in Google to prevent this?
The first time the sync runs this may change the column type in Coda. After you set the column type to the format you want, future syncs from Google to Coda shouldn’t change the format.
Exception: Request failed for https://coda.io returned code 404. Truncated server response: {“statusCode”:404,“statusMessage”:“Not Found”,“message”:“Doc does not exist or is inaccessible.”} (use muteHttpExceptions option to examine full response) (line 409, file “Coda”)
Thank you, Al, it works for the Coda to Gsheet part.
Then I start the Gsheet to Coda sync and encountered another error:
ReferenceError: CodaAPI is not defined (line 9, file “Code”)
Which indicates an error with the API key? I generated a new API token and click the button to copy the key here, not sure why it does not work? I tried deleting the old token and created (several) new ones but again, not working.
@Tu_Bui that might mean you didn’t load the library for the Coda API. If you created a new project in Google Apps Script, you may have to add in the library again.
Hm not too sure, did you make sure the spelling and capitalization of your columns in your Google Sheet match exactly with the columns in your Coda table?
The column names in Gsheet are correct but 2 of them have identical names so when copied to Coda, they automatically changed to “column name 2” and thus cause a discrepancy in syncing.
Hi @Marc_Fitt, if you’re trying to sync rows of data from a view to a Google Sheet, you can just use the ID from the view in the script and the filtered data should sync over.
Hi @Marc_Fitt, when you provide the ID for the main table that you are trying to sync (and that main table is filtered), you’re saying only the filtered data gets synced to your Google Sheet? I think that error may be a result of two things:
The first row in your Google Sheet does not contain your header columns (row 1 has to be your headers)
The script isn’t finding the Coda source row URLs in your Google Sheet. This may be related to my first question, but perhaps try clearing all the data in your Google Sheet and run the sync fresh to make sure all the source row URLs get copied correctly to your Google Sheet.
@Marc_Fitt I see I think this might be the intended behavior of the listRows endpoint in the API. This endpoint has a query parameter which means the table should be unfiltered and then you would edit the query parameter to filter out any rows you don’t need on the sync. I’ll check internally to see if this is the case. The workaround is to have a page with the unfiltered table which you would sync to Google Sheets.
I noticed you have two scripts in the same Google Apps Script project. I’ve found that this may lead to functions crossing paths so I would create one unique project for each script. When functions are named the same between scripts in the same project, it leads to unexpected behavior.
I’d also recommend removing the Loom video from your post since your API key is visible in the video
Good point for the Api. I thought combining all my scripts for the same purpose would be better so they are all triggered at the same time. I run the same scripts for multiple tables on the same doc to back up them and use Google sheet as a bigger database.
Another quick question:
If I use the formula to prevent deleting rows on google sheet, will it add the same rows over and over again or update the existing row created the first time in google sheet?
There is a visibleOnly flag in the API which should allow you to get all the data from the table regardless if the table is filtered. Looking into this some more and will report back once there’s an answer!
For the formula to prevent deleting rows, which formula are you referring to specifically?