write_document

Create a draft, edit it, comment on it, archive it, or send it to a person for approval with an API key.

Reference

At a glance

ActionNeedsSend
createdocuments:createtopic, name, body, no documentId
editdocuments:editdocumentId and edits
commentdocuments:commentdocumentId and comment
archivedocuments:deletedocumentId and "status": "Archived"
send_for_approvaldocuments:send-for-approvaldocumentId and sendForApproval

A key works on drafts. It cannot publish a document, approve one or send one back: the approver does that in Alchex. Every answer is 200 with a message, and most carry a link to the document.

A key cannot delete a document: deleting needs a team Owner, and a key is never one. Archive the document instead. write_document/delete answers 404 tool_not_found, and "status": "Deleted" sent to archive answers 403 not_allowed_for_api_key.

Create a draft

bash
curl -X POST https://app.alchex.com/api/v1/tools/write_document/create \  -H "Authorization: Bearer EXAMPLE_API_KEY" \  -H "Content-Type: application/json" \  -d @supplier-exit-plan.json
json
{  "topic": "supplier-exit",  "name": "Supplier exit plan",  "documentType": "Document",  "body": "# Supplier exit plan\n\nOwner: Head of Procurement\nApplies to: All critical suppliers\nReview: Every year\n\n## Purpose\n…\n## Scope\n…\n## Roles and Responsibilities\n…\n## Content\n…\n## Review\n…\n## References\n…"}
FieldRequiredWhat it is
topicYesA short word for what the document covers, up to 80 characters
nameYesThe title, up to 200 characters
bodyYesThe text in Markdown, up to 60,000 characters
documentTypeNoSuch as Policy or Procedure. It decides the sections.
teamIdNoThe team that owns it, by id or name

The body must read as finished:

  • It starts with # and the title, then lines naming the owner, what it applies to, and when it is reviewed.
  • Its ## sections are exactly its type's, in order. A policy has Purpose, Scope, Roles and Responsibilities, Policy Statements, Implementation, Exceptions, Compliance, Review and References. A procedure has Purpose, Scope, Roles and Responsibilities, Procedure, Records, Exceptions, Review and References. Any other type has the six sections above.
  • It has no text in square brackets left to fill in.

A body that breaks a rule is refused with 400 and a code: not_reader_ready, structure_differs or placeholder_in_body. The message says what to fix.

Edit a draft

json
{ "documentId": "DOCUMENT_ID", "edits": [ { "find": "every two years", "replace": "every year" } ] }

Each edit replaces the exact text in find with replace, up to 100 edits a request. An empty find adds replace at the end. An empty replace removes the text. Text a person changed since is not overwritten: the edit waits as a suggestion, and the message says so.

Comment

ToSend comment as
Start a thread{ "text": "Check the notice period.", "quote": "30 days" }
Reply{ "thread": "THREAD_ID", "text": "…" }
Resolve or reopen{ "thread": "THREAD_ID", "resolved": true }

quote is optional text from the document that the new thread points at.

Archive

json
{ "documentId": "DOCUMENT_ID", "status": "Archived" }

Send nothing else with it. A document a control depends on cannot be archived.

Send for approval

json
{ "documentId": "DOCUMENT_ID", "sendForApproval": { "approver": "alex@example.com", "note": "Ready for the yearly review." } }

Name the approver by name or email. Left out, Alchex picks the only person who may approve; with several, it is refused with 400 refused, and the message lists them. The approver decides on a fixed copy; the draft stays editable meanwhile.