Sync a register from a spreadsheet
Send the rows of a spreadsheet into a list register with a short script, and run it again without adding a row twice.
What you'll do
Export a spreadsheet as CSV and send its rows into a list register in batches of 50. Running the script again with the same file adds nothing.
Before you start
- A list register whose column names match the spreadsheet's headings. A heading with no matching column is refused.
- An API key with
registers:rows:add. See Create and manage API keys. - Python 3 on the computer that runs the script.
Steps
- Open the register in Alchex and check its column names match your spreadsheet's headings exactly.
- In your spreadsheet app, save the sheet as CSV, with the headings in the first row.
- Save this script as sync.py next to the CSV file.
- In a terminal, run the script with your key, the file and the register's name.
- Open the register in Alchex and check the new rows.
What happens next
Each batch answers 201 with the new rowIds. A batch already sent answers 200, and nothing is added. The rows count at once, under the key's name.
The script adds rows; it does not change rows already there. A row you edited in the spreadsheet is a new batch, so it is added again. To update rows instead, read them with read_document/rows and send write_record/change; see Rows.
If something goes wrong
400 unknown_field. A heading is not a column of the register, and the message lists the columns. Rename the heading to match.
404 register_not_found. Check the register's name, or use its code.
403 missing_permission. The key lacks registers:rows:add. Create a key with it.
413 body_too_large. A batch is over 200 KB. Change 50 to a smaller number in both places.