Skip to content
MantraWorx
Developers › Documents API

Developers

Documents API

List, read, create and update documents, and avoid overwriting a newer edit.

ReferenceContent reviewed

On this page

Use the Documentation API to list, read, create and update documents. Establish a session first.

Access requirements#

EndpointComponent gateAdditional requirement
GET /api/documentation/documentsdocs.documents: viewOnly accessible records are returned.
GET /api/documentation/documents/:idviewRead access to the document.
POST /api/documentation/documentswriteDestination access and permitted fields.
PUT /api/documentation/documents/:idwriteDocument write access; audience changes can require admin access.
DELETE /api/documentation/documents/:idwriteAdministrative access to this document.
GET /api/documentation/documents/:id/versionsviewAccess to the document.
POST /api/documentation/documents/:id/versions/:versionNumber/restorewriteAccess required to restore the document.
GET /api/documentation/foldersviewOnly accessible folders are returned.

All levels refer to docs.documents. See Permissions.

List documents#

GET /api/documentation/documents

QueryMeaning
pageDefaults to 1; minimum 1.
limitDefaults to 20; constrained to 1–200.
statusdraft, review, published or archived.
visibilityprivate, department, project or public.
searchSearch titles and text.
tagsComma-separated tags.
departmentIdRestrict to a department within your accessible scope.
sortBycreated_at, updated_at, title or status; default updated_at.
sortOrderasc or desc; default desc.
includeContentInclude bodies when true; false by default.
js
const response = await fetch(
  "/api/documentation/documents?status=published&limit=20",
  { credentials: "same-origin" },
);
if (!response.ok) throw new Error(`Document list: ${response.status}`);
const { documents, pagination } = await response.json();

Use pagination.hasMore to check for another page. Do not assume the default response includes an exact total.

Create a document#

POST /api/documentation/documents requires a title.

FieldTypeMeaning
titlestringDocument title.
contentstringBody.
content_typestringhtml, markdown or plain.
summarystringShort description.
statusstringLifecycle state, subject to workflow checks.
visibilitystringIntended audience, subject to access checks.
folder_idstringDestination folder identifier.
tagsstring arrayLabels.

This function uses the caller's content to create a private draft.

js
async function createDraft(title, markdown) {
  const response = await fetch("/api/documentation/documents", {
    method: "POST",
    credentials: "same-origin",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify({
      title, content: markdown, content_type: "markdown",
      status: "draft", visibility: "private",
    }),
  });
  const result = await response.json();
  if (!response.ok) throw new Error(result.error ?? "Create failed");
  return result;
}

Success returns HTTP 201 and the created document. Verify its identifier, audience and content. Internal public visibility does not mean internet publication; see Website guides.

Update without overwriting a newer edit#

Read the document first. Send its last-read updated_at as baseUpdatedAt.

js
async function updateTitle(document, title) {
  const response = await fetch(
    `/api/documentation/documents/${encodeURIComponent(document.id)}`,
    {
      method: "PUT",
      credentials: "same-origin",
      headers: { "Content-Type": "application/json" },
      body: JSON.stringify({
        title, baseUpdatedAt: document.updated_at,
      }),
    },
  );
  const result = await response.json();
  if (response.status === 409 && result.code === "DOCUMENT_CONFLICT") {
    return { conflict: true, currentUpdatedAt: result.currentUpdatedAt };
  }
  if (!response.ok) throw new Error(result.error ?? "Update failed");
  return { conflict: false, document: result };
}

Recover from DOCUMENT_CONFLICT#

HTTP 409 fieldValue or type
successfalse
codeDOCUMENT_CONFLICT
errorDescription of the concurrent modification.
currentUpdatedAtCurrent timestamp, or null if unavailable.
  1. Preserve your unsaved changes.
  2. Fetch the latest document.
  3. Reconcile your changes with the latest content.
  4. Send the merged update with the new document's updated_at.
  5. Handle another conflict if someone saves again.

Do not only replace the timestamp and resend stale content; that discards the other person's changes.

Deletion and failures#

Deletion requires administrative access to the target document. Confirm the target and child-document implications before calling it. A 403 can mean missing component access or insufficient document access. Read Errors and rate limits before adding automatic retries.

Need more help?

Can’t find what you need? Talk to the team.

To report a problem with this guide, include its title and the step that blocked you.

Contact support