Node-Red is a graphical, flow based program usually used to control or monitor Internet of Things devices. However it is also handy to interact with APIs, including the one for Grist. Here is an example workflow to perform a timed backup of a Grist database:
Here is an overview of a simple flow. Note there isn’t any error recovery or monitoring beyond a debug mode - this is just to get you started:
And here are the modules I am using. There is a dedicated Grist module to make things easy, although it does seem to have one bug:
(Note I am using the “Cron Plus” injection node because the standard injection node wouldn’t fire at a set time in my Linux Docker environment - your mileage may vary)
Note that there seems to be a bug in the Grist module so when you select to download the Grist document as Excel it actually comes down in SQLite format (native Grist format) and when you pick Grist it comes down as Excel. Here I want the SQLite so I picked “Excel” ¯_(ツ)_/¯. However check the actual file it downloads to make sure you are getting the correct format you want or just do this part twice, once for Excel and once for Grist to make sure you get both types:
When setting up the Grist node, you will need to set up a document and a server. Here is how to set up the document portion. The Document ID is available in you Grist document under “Settings” at the bottom:
Next we need to set up the server part. The URL you need to enter varies a little bit if you are using a team. Here is the standard, just a normal user one. Note your API key is available under the account information of the main owner of the document:
If you are using a team, you need to put your team name instead of “docs” in the URL:
Finally we just need to write out the file it downloads. Your file path will likely be different. In my Docker server Node Red has access to a “data” folder so I store the file there:
Finally make sure you add a Debug node like is shown and Deploy and run your Node Red script. If you get any errors, double check the Document ID, API key and Grist URL - those are the likely places to go wrong.
Assuming everything is working just set up the Injection (starter) node to run on a regular basis to automatically back up your Grist document to a local drive