Back up published documents
Save the text of your published documents to files with a short script, and see which ones have changes since they were published.
What you'll do
Save each published document's text as a Markdown file. The script also tells you which documents have edits since they were published, so you know the file holds those edits too.
Before you start
- An API key with
documents:search,documents:text:readandregisters:changes:read. See Create and manage API keys. - Python 3 on the computer that runs the script.
Steps
- Find each document's id by searching for its name or code.
- Copy the
idfromdocuments.candidatesinto a file named ids.txt, one id per line. - Save this script as backup.py next to ids.txt.
- In a terminal, run the script with your key.
- Open the backup folder and check one file per document.
What happens next
Each file holds the document's current text. Where the script says with edits since publishing, the file includes edits nobody has approved yet. Read them with read_document/changes, or wait until the next version is published and run the script again.
Each document costs a few requests. With many documents, the key may meet the limit of 60 a minute; see Rate limits, retries and cost.
If something goes wrong
404 not_found. The id is wrong, or the document is in no team the key reaches. Search for it again.
403 missing_permission. The key lacks the permission the message names. Create a key with all three.
A document is skipped as never published. It has no published version yet. Publish it in Alchex first.