Skip to content
SharpWrite
Docs menu

API reference

A small, read-only JSON API. It is the same on SharpWrite Cloud and on Self-host; only the base address differs.

Base address and authentication

Cloud: https://app.sharpwritecms.com. Self-host: the address of your own install. Every request needs an API key as a bearer token:

Authorization: Bearer sw_live_YOUR_KEY

Machine-readable: the OpenAPI description of these endpoints, and the AI reference for assistants.

Create and revoke keys in the app under MCP. A revoked key stops working immediately. A key belongs to one site and can only read that site. Keep keys on your server.

List entries

GET /api/public/v1/{type}?limit=20&offset=0

{type} is the API id of the content type (for example posts). limit is 1 to 100 (default 20) and offset is 0 or more. Only published entries are returned, newest first.

Response
{
  "data": [
    {
      "id": "6f1c…",
      "slug": "hello-world",
      "publishedAt": "2026-12-01T09:30:00.000Z",
      "updatedAt": "2026-12-02T10:00:00.000Z",
      "data": {
        "title": "Hello world",
        "body": "<p>Rich text arrives as HTML.</p>"
      }
    }
  ],
  "pagination": { "limit": 20, "offset": 0, "count": 1 }
}

Get one entry

GET /api/public/v1/{type}/{slug}

Returns { "data": { … } } with the same entry shape. A draft or unknown slug answers 404.

Field values

  • Short text, long text and choice lists arrive as strings, numbers as numbers, yes/no as booleans and dates as YYYY-MM-DD.
  • Rich text arrives as sanitised HTML. Images inside it use full addresses, so they work on your own domain.
  • Only fields that currently exist on the type are returned. Internal ids and drafts are never exposed.

Draft preview

To read drafts as well (for a private preview route on your site), send a preview token next to the API key. Create one under Draft preview; it can expire and can be revoked at any time.

curl https://YOUR-SHARPWRITE/api/public/v1/posts/my-draft \
  -H "Authorization: Bearer sw_live_YOUR_KEY" \
  -H "X-Preview-Token: sw_prev_YOUR_TOKEN"
  • The list then contains drafts and published entries (most recently changed first) and each entry has a status field of draft or published.
  • A preview token never works without an API key, only for its own site, and a wrong or expired token is a 401 (it never silently falls back to published-only).
  • Preview responses are private, no-store. Never put a preview token in a page that visitors can read.

Webhooks

Add webhooks under Webhooks. SharpWrite sends a POST with a JSON body when:

  • entry.published: an entry was published (or created as published)
  • entry.updated: a published entry changed (including a version restore)
  • entry.unpublished: a published entry went back to draft
  • entry.deleted: a published entry was deleted
  • test: you pressed "Send test"

Saving a draft over a draft, or deleting a draft, sends nothing.

Body
{
  "id": "0d5e…",
  "event": "entry.published",
  "createdAt": "2026-12-01T09:30:00.000Z",
  "site": { "id": "…", "name": "My site" },
  "type": { "apiId": "posts", "name": "Posts" },
  "entry": { "id": "…", "slug": "hello-world", "status": "published" }
}

The payload names the entry but does not contain its content: call the API for that. Every call carries these headers:

X-SharpWrite-Event: entry.published
X-SharpWrite-Timestamp: 1796117400
X-SharpWrite-Signature: v1=<hex HMAC-SHA256 of "{timestamp}.{body}" with your signing secret>
Verify the signature (Node.js)
import { createHmac, timingSafeEqual } from "node:crypto";

function verify(secret, timestamp, rawBody, signature) {
  const expected = "v1=" + createHmac("sha256", secret).update(`${timestamp}.${rawBody}`).digest("hex");
  const a = Buffer.from(expected);
  const b = Buffer.from(signature);
  const fresh = Math.abs(Date.now() / 1000 - Number(timestamp)) < 300; // reject replays
  return fresh && a.length === b.length && timingSafeEqual(a, b);
}
  • The URL must be https:// and public. Redirects are not followed. Answer within 8 seconds with any 2xx status.
  • A failing or slow webhook never blocks publishing. The last 25 deliveries of each webhook are kept so you can see what went wrong. A deploy hook does not need the signature.
  • Up to 5 webhooks per site. The signing secret is shown once when you create it; "New secret" replaces it.

AI agents (MCP)

Besides this REST API, SharpWrite has an MCP endpoint at /api/mcp that uses the same API keys. AI agents can read entries and, with a key that allows it, save and edit drafts. They can never publish or delete. See AI agents (MCP).

Errors, caching and limits

Error shape
{ "error": { "message": "Invalid or revoked API key." } }
  • 400 invalid query, 401 missing, invalid or revoked key (or preview token), 404 unknown type or entry, 429 too many requests.
  • Each key may make 120 requests a minute; the Retry-After header says when to try again.
  • Published responses send Cache-Control: public, s-maxage=30, stale-while-revalidate=300, so a CDN can cache them briefly.
  • CORS allows any origin for GET, but remember that a key in browser code is visible to everyone. Call the API from your server or at build time.
  • The API keeps working when a plan lapses (Cloud) or a license is switched off (Self-host): your live website never goes down because of billing.