How to guard API document writes
Use a write precondition when your integration should update or delete only the version of a note it previously read. You need API access to the shared Space. See the API documentation for authentication and request schemas.
Read the full note with
GET /api/v1/spaces/{accessKey}/documents/{docId}. Keep the returnedmodifiedAttimestamp orcontentXxHash32hash.Prepare the complete replacement Markdown. Send it to the same URL with
PUT, using the savedcontentXxHash32asexpectedContentXxHash32.{"content":"# Review notes\n\nThe figures are ready.","expectedContentXxHash32":"30b392a3"}Use your own returned hash in place of the example. You can send the saved timestamp as
expectedModifiedAtinstead, or include both guards to require that both match. If the update succeeds, keep the timestamp and hash from the response for your next write.If you receive HTTP
409, read the latest note and reconcile the changes. Retry with the timestamp or hash from that read.
The hash covers the whole note. A hash-only guard can match if the note returns to the same text. A PUT replaces the whole note, so start from a full read when editing just one section.
To guard a deletion, send expectedModifiedAt, expectedContentXxHash32, or both as query parameters on the DELETE request. For example, append ?expectedContentXxHash32=30b392a3 using the hash of the note you reviewed.