
# API overview

The Sitepaste API lets you manage pages, upload media, and deploy your site programmatically, whether from a script, a CI pipeline, a phone shortcut, or any HTTP client. It is available on the Pro plan. Billing, team management, and sending mail to your subscribers have no endpoints and stay in the dashboard.

If you are new to Sitepaste, start with [Getting started](/guides/getting-started) for the core concepts.

## Base URL

```sh
https://sitepaste.com/api/v1/public
```

## Endpoints

Each endpoint has its own reference page. The groups below match the [scope](/api/authentication#scopes) a token needs to reach them.

Publishing a page end to end takes four requests: [POST /sites/{siteId}/pages](/api/pages/post-pages) writes it, [POST /media](/api/media/post-media) uploads anything it shows, [POST /sites/{siteId}/deployments](/api/deployments/post-deployments) puts it live, and [GET /sites/{siteId}/pages/{pagePath}](/api/pages/get-pages-path) reads it back. Every other endpoint is a GET, POST, PATCH, or DELETE over one of the resources below.

### Pages

Requires the `content` scope.

| Method | Path | Purpose |
|--------|------|---------|
| POST | [/sites/{siteId}/pages](/api/pages/post-pages) | Create one page on a site |
| POST | [/sites/{siteId}/pages/batch](/api/pages/post-pages-batch) | Create, update, and delete many pages in one request |
| GET | [/sites/{siteId}/pages](/api/pages/get-pages) | List page metadata for a site, including the IDs used for renames |
| GET | [/sites/{siteId}/pages/{pagePath}](/api/pages/get-pages-path) | Read a single page's full record, content included |
| PATCH | [/sites/{siteId}/pages/{pagePath}](/api/pages/patch-pages-path) | Update one page at its own URI, without sending a batch |
| DELETE | [/sites/{siteId}/pages/{pagePath}](/api/pages/delete-pages-path) | Delete a single page at its own URI |

### Authors

Requires the `content` scope.

| Method | Path | Purpose |
|--------|------|---------|
| GET | [/sites/{siteId}/authors](/api/authors/get-authors) | List a site's authors and the IDs used to credit pages to them |
| POST | [/sites/{siteId}/authors](/api/authors/post-authors) | Create an author on a site |
| GET | [/sites/{siteId}/authors/{authorId}](/api/authors/get-authors-id) | Read one author's record |
| PATCH | [/sites/{siteId}/authors/{authorId}](/api/authors/patch-authors-id) | Update an author's fields by id |
| DELETE | [/sites/{siteId}/authors/{authorId}](/api/authors/delete-authors-id) | Delete an author by id |

### Events and event types

Requires the `content` scope.

| Method | Path | Purpose |
|--------|------|---------|
| GET | [/sites/{siteId}/events](/api/events/get-events) | List a site's events, hidden ones included |
| POST | [/sites/{siteId}/events](/api/events/post-events) | Create one event on a site |
| POST | [/sites/{siteId}/events/batch](/api/events/post-events-batch) | Create, update, and delete many events in one request |
| GET | [/sites/{siteId}/events/{eventId}](/api/events/get-events-id) | Read one event's record, hidden ones included |
| PATCH | [/sites/{siteId}/events/{eventId}](/api/events/patch-events-id) | Update one event at its own URL, without sending a batch |
| DELETE | [/sites/{siteId}/events/{eventId}](/api/events/delete-events-id) | Delete a single event by id |
| GET | [/sites/{siteId}/event-types](/api/events/get-event-types) | List a site's event types in display order |
| POST | [/sites/{siteId}/event-types](/api/events/post-event-types) | Create one event type on a site |
| POST | [/sites/{siteId}/event-types/batch](/api/events/post-event-types-batch) | Upsert event types by slug, with deletes in the same call |
| PATCH | [/sites/{siteId}/event-types](/api/events/patch-event-types) | Set the display order of a site's event types by slug |
| GET | [/sites/{siteId}/event-types/{slug}](/api/events/get-event-types-slug) | Read one event type by its slug |
| PATCH | [/sites/{siteId}/event-types/{slug}](/api/events/patch-event-types-slug) | Update one event type at its own URL |
| DELETE | [/sites/{siteId}/event-types/{slug}](/api/events/delete-event-types-slug) | Delete a single event type by slug |

### Sections and tags

Requires the `content` scope.

| Method | Path | Purpose |
|--------|------|---------|
| GET | [/sites/{siteId}/sections](/api/sections/get-sections) | List a site's sections with page counts and metadata |
| PATCH | [/sites/{siteId}/sections](/api/sections/patch-sections) | Write the full nav-group order in one atomic request |
| GET | [/sites/{siteId}/sections/{sectionPath}](/api/sections/get-sections-contenttype) | Read one section with its page count and metadata |
| PATCH | [/sites/{siteId}/sections/{sectionPath}](/api/sections/patch-sections-contenttype) | Set a section's display title, description, and nav position |
| DELETE | [/sites/{siteId}/sections/{sectionPath}](/api/sections/delete-sections-contenttype) | Delete a section, every page in it, and the metadata that names it |
| GET | [/sites/{siteId}/tags](/api/tags/get-tags) | List a site's tags with page counts and metadata |
| GET | [/sites/{siteId}/tags/{slug}](/api/tags/get-tags-slug) | Read one tag with its page count and metadata |
| PATCH | [/sites/{siteId}/tags/{slug}](/api/tags/patch-tags-slug) | Rename a tag across the site, set its display title and description, or both |
| DELETE | [/sites/{siteId}/tags/{slug}](/api/tags/delete-tags-slug) | Remove a tag from every page and drop its metadata |

### Media and uploads

Requires the `media` scope. The library is shared by every site in the workspace, so these routes are not site-scoped. There are two ways in: [POST /media](/api/media/post-media) sends the file through the request, and `/uploads` hands back upload URLs that a large file is sent to directly.

| Method | Path | Purpose |
|--------|------|---------|
| POST | [/media](/api/media/post-media) | Upload a single file and get its URL to reference in content |
| GET | [/media](/api/media/get-media) | List the files in the workspace media library |
| PATCH | [/media?fileIds=](/api/media/patch-media) | Move a set of files into a folder, or note them, in one request |
| DELETE | [/media?fileIds=](/api/media/delete-media) | Delete a set of media files in one request |
| GET | [/media/folders](/api/media/get-media-folders) | List the workspace's media folders in display order |
| POST | [/media/folders](/api/media/post-media-folders) | Create a media folder (photographer galleries) |
| GET | [/media/folders/{folderId}](/api/media/get-media-folders-folderid) | Read one media folder |
| PATCH | [/media/folders/{folderId}](/api/media/patch-media-folders-folderid) | Rename a media folder, or reorder the media inside it |
| DELETE | [/media/folders/{folderId}](/api/media/delete-media-folders-folderid) | Delete a media folder; its files return to the library root |
| GET | [/media/{fileId}](/api/media/get-media-fileid) | Read one file's record from the media library |
| PATCH | [/media/{fileId}](/api/media/patch-media-fileid) | Set a file's note, move it between folders, or both |
| DELETE | [/media/{fileId}](/api/media/delete-media-fileid) | Delete a single media file from the library |
| POST | [/uploads](/api/media/post-uploads) | Get the upload URLs to send a file to directly |
| GET | [/uploads/{uploadId}](/api/media/get-uploads-uploadid) | Read an upload's state: whether its bytes have landed yet |
| POST | [/uploads/{uploadId}/complete](/api/media/post-uploads-complete) | Validate an uploaded file and add it to the media library |
| DELETE | [/uploads/{uploadId}](/api/media/delete-uploads-uploadid) | Abort an upload in progress |

### Deploys and previews

Requires the `deploy` scope.

| Method | Path | Purpose |
|--------|------|---------|
| POST | [/sites/{siteId}/deployments](/api/deployments/post-deployments) | Queue a deploy that publishes your saved pages as a static site |
| GET | [/sites/{siteId}/deployments](/api/deployments/get-deployments) | List recent deploys with status and attribution |
| GET | [/sites/{siteId}/deployments/latest](/api/deployments/get-deployments-latest) | Get the most recent deploy's status for a site |
| GET | [/sites/{siteId}/deployments/live](/api/deployments/get-deployments-live) | Read the deploy currently serving the site |
| DELETE | [/sites/{siteId}/deployments/live](/api/deployments/delete-deployments-live) | Take a site offline, keeping all content |
| GET | [/sites/{siteId}/deployments/{deploymentId}](/api/deployments/get-deployments-id) | Read one deploy from the site's history |
| GET | [/sites/{siteId}/pending-changes](/api/deployments/get-pending-changes) | See what changed since the last deploy |
| POST | [/sites/{siteId}/previews](/api/previews/post-previews) | Build the site to a shareable preview before deploying |
| GET | [/sites/{siteId}/previews](/api/previews/get-previews) | List a site's active previews |
| GET | [/sites/{siteId}/previews/{previewId}](/api/previews/get-previews-previewid) | Read one preview's status and URL |
| PATCH | [/sites/{siteId}/previews/{previewId}](/api/previews/patch-previews-previewid) | Change a preview's visibility or password |
| DELETE | [/sites/{siteId}/previews/{previewId}](/api/previews/delete-previews-previewid) | Expire a preview and remove its output |
| POST | [/sites/{siteId}/previews/{previewId}/rebuild](/api/previews/post-previews-rebuild) | Rebuild a preview with the current content |
| POST | [/sites/{siteId}/previews/{previewId}/promote](/api/previews/post-previews-promote) | Swap a ready preview into the live site |

### Workspace, sites, and domains

Requires the `settings` scope.

| Method | Path | Purpose |
|--------|------|---------|
| GET | [/workspace](/api/workspace/get-workspace) | Read the workspace a token acts on, and which site is its default |
| PATCH | [/workspace](/api/workspace/patch-workspace) | Make a site the workspace default |
| GET | [/sites](/api/sites/get-sites) | List the workspace's sites with the site limit |
| POST | [/sites](/api/sites/post-sites) | Create a site within the paid allowance |
| GET | [/sites/{siteId}](/api/sites/get-sites-siteid) | Read one site's full settings by id |
| PATCH | [/sites/{siteId}](/api/sites/patch-sites-siteid) | Update one site's settings by id |
| DELETE | [/sites/{siteId}](/api/sites/delete-sites-siteid) | Delete a site and everything on it |
| GET | [/domains](/api/domains/get-domains) | List custom domains with status and the domain limit |
| POST | [/domains](/api/domains/post-domains) | Add a custom domain and receive its DNS setup records |
| GET | [/domains/{domainId}](/api/domains/get-domains-domainid) | Read one custom domain's status and DNS records |
| PATCH | [/domains/{domainId}](/api/domains/patch-domains-domainid) | Point a domain at a different site in the workspace |
| DELETE | [/domains/{domainId}](/api/domains/delete-domains-domainid) | Remove a custom domain from the workspace |
| POST | [/domains/{domainId}/check](/api/domains/post-domains-check) | Check the domain's DNS and move it on to its next status |

### Submissions, subscribers, and metrics

Requires the `data` scope.

| Method | Path | Purpose |
|--------|------|---------|
| GET | [/sites/{siteId}/contact-submissions](/api/data/get-contact-submissions) | List a site's contact form submissions |
| GET | [/sites/{siteId}/contact-submissions/{submissionId}](/api/data/get-contact-submissions-id) | Read one contact form submission |
| DELETE | [/sites/{siteId}/contact-submissions/{submissionId}](/api/data/delete-contact-submissions-id) | Delete one contact form submission |
| GET | [/sites/{siteId}/newsletter-subscribers](/api/data/get-newsletter-subscribers) | List a site's newsletter subscribers |
| POST | [/sites/{siteId}/newsletter-subscribers](/api/data/post-newsletter-subscribers) | Add a newsletter subscriber directly |
| GET | [/sites/{siteId}/newsletter-subscribers/{subscriberId}](/api/data/get-newsletter-subscribers-id) | Read one newsletter subscriber's record |
| PATCH | [/sites/{siteId}/newsletter-subscribers/{subscriberId}](/api/data/patch-newsletter-subscribers-id) | Update a subscriber's fields or confirm them |
| DELETE | [/sites/{siteId}/newsletter-subscribers/{subscriberId}](/api/data/delete-newsletter-subscribers-id) | Remove a newsletter subscriber |
| GET | [/sites/{siteId}/metrics](/api/data/get-metrics) | Read a site's traffic metrics |

## Authentication

Every request requires a bearer token in the `Authorization` header:

```
Authorization: Bearer sp_your_token_here
```

Tokens are created in the dashboard under Account > Tokens, where each token is given the scopes it may use: content, media, settings, deploy, and data. Each endpoint requires exactly one scope, and a token missing it gets a 403 whose `code` is `token_scope_required` and whose `scope` field names the scope. Writing content needs `content` and publishing it needs `deploy`, in two requests. See [authentication](/api/authentication).

## Quick example

```bash
TOKEN="sp_your_token_here"

# Write the page
curl -X POST https://sitepaste.com/api/v1/public/sites/default/pages \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "title": "Hello world",
    "content": "# Hello world\n\nPublished via the API.",
    "tags": ["first-post"]
  }'

# Publish it
curl -X POST https://sitepaste.com/api/v1/public/sites/default/deployments \
  -H "Authorization: Bearer $TOKEN"
```

Saving a page does not publish it.

## Addressing

A workspace's resources hang off the root; a site's hang off that site:

```
/workspace  /sites  /domains  /media  /uploads      the workspace
/sites/{siteId}/...                                 one site in it
```

The workspace comes from your token, so it never appears in the path. One media
library serves every site in the workspace, so `/media` sits at the root, while
each page belongs to one site under `/sites/{siteId}/pages`.

`{siteId}` takes a site's short ID or the literal `default`:

```bash
curl https://sitepaste.com/api/v1/public/sites/default/pages \
  -H "Authorization: Bearer $TOKEN"
```

`default` resolves to the workspace's default site at request time. A stored
URI holding `default` follows the default if you change it later; one holding a
site's own ID does not. Use `default` interactively, and the ID in anything you
save, schedule, or share.

Query parameters such as `?limit=`, `?offset=`, `?q=`, and `?type=` filter and
window a collection. The two bulk media routes,
[`PATCH /media?fileIds=a,b`](/api/media/patch-media) and
[`DELETE /media?fileIds=a,b`](/api/media/delete-media), name their files in
`?fileIds=`, and the PATCH body carries what to write.

Under `/sites/{siteId}`, the path names the site, so no body carries a `siteId`.

### Action sub-resources

Four routes start an action on the resource above them:

```
POST /domains/{domainId}/check         POST /previews/{previewId}/rebuild
POST /uploads/{uploadId}/complete      POST /previews/{previewId}/promote
```

Each starts work, and none is idempotent: asking twice does the work twice
unless you send an [`Idempotency-Key`](#idempotency). A GET on one is a
405. Read the result at the parent: `/domains/{domainId}`,
`/previews/{previewId}`, or `/uploads/{uploadId}`.

### What a collection POST means

A POST to a collection creates one member and answers 201 with a
`Location` naming it. Use the `/batch` sub-resource below to write many members
at once.

Three routes answer differently:

| Route | Answers |
|---|---|
| [POST /sites/{siteId}/deployments](/api/deployments/post-deployments) | 202, with `Location` naming the deploy to poll |
| [POST /sites/{siteId}/previews](/api/previews/post-previews) | 202, with `Location` naming the preview to poll |
| [POST /domains](/api/domains/post-domains) | 201 with no `Location`, since an apex domain and its `www.` pair are created together |

Three collections also have a `/batch` sub-resource. Send it the envelope and
it applies many writes at once, atomically, answering 200 with a report:

| Collection | Batch route | Envelope |
|---|---|---|
| [/sites/{siteId}/pages](/api/pages/post-pages) | [/pages/batch](/api/pages/post-pages-batch) | `{"pages": [...], "deleteSlugs": [...]}` |
| [/sites/{siteId}/events](/api/events/post-events) | [/events/batch](/api/events/post-events-batch) | `{"events": [...], "deleteIds": [...]}` |
| [/sites/{siteId}/event-types](/api/events/post-event-types) | [/event-types/batch](/api/events/post-event-types-batch) | `{"eventTypes": [...], "deleteSlugs": [...]}` |

A create answers 409 on a member that already exists. A batch entry upserts
instead, so re-sending the same batch lands the same state. Use `/batch` to
mirror content or to land several writes together, and the collection to write
a single member.

### What a collection PATCH means

A PATCH on a collection writes across its members in one request. The URI
says which members, and the body says what to write:

| Route | Selects | Body | Writes |
|---|---|---|---|
| [/sites/{siteId}/event-types](/api/events/patch-event-types) | the whole collection | `{"order": [...]}` | the display order |
| [/sites/{siteId}/sections](/api/sections/patch-sections) | the whole collection | `{"order": [...]}` | the nav-group order |
| [/media?fileIds=](/api/media/patch-media) | the files the query names | `{"folderId": ..., "note": ...}` | one change across them |

## Request bodies

Send `Content-Type: application/json` on every request that carries a body. An endpoint that receives a body in a format it does not parse answers 415. The exceptions take `multipart/form-data`: [POST /media](/api/media/post-media), and the two page-write routes, [POST /sites/{siteId}/pages](/api/pages/post-pages) and [POST /sites/{siteId}/pages/batch](/api/pages/post-pages-batch), when they carry [inline media](/api/media/inline-media). A 415 refusing a PATCH body also names the formats that route does take, in `Accept-Patch`.

Every PATCH is a partial write: a field you send is written, a field you omit keeps its stored value. An empty string clears a field, and `null` reads as not sent. A PATCH body sent as `application/merge-patch+json` is refused with 415. Where `null` means something on a particular field, that field's own page says so: `folderId` on [PATCH /media/{fileId}](/api/media/patch-media-fileid) takes `null` to unfile a file.

No endpoint reads a request body on DELETE. Deletes that act on several things name them in the query: [DELETE /media?fileIds=a,b](/api/media/delete-media).

A field that belongs to a neighbouring endpoint is refused with a 422 naming it, and the error says which route takes it. That covers `siteId`, which is named in the path; a batch envelope's keys on a route that writes one record; and `fileIds` on [PATCH /media](/api/media/patch-media), which names its files in the query.

## Response format

All responses are JSON unless you ask for something else. Two collections serve a second representation, chosen with `Accept`:

| Request | Response |
|---------|----------|
| `GET /sites/{siteId}/pages` | Page metadata as JSON |
| `GET /sites/{siteId}/pages` with `Accept: application/zip` | Every page as a zip of Markdown |
| `GET /sites/{siteId}/newsletter-subscribers` | Subscribers as JSON |
| `GET /sites/{siteId}/newsletter-subscribers` with `Accept: text/csv` | Subscribers as CSV |

An `Accept` header that rules out every representation an endpoint can produce gets a 406.

## Errors

Every error answers with the same envelope, whatever went wrong:

```json
{
  "error": "validation failed",
  "code": "validation_failed",
  "fields": {
    "slug": "slug must not be empty"
  }
}
```

| Member | Meaning |
|--------|---------|
| `error` | A sentence to show a user. Do not match on it; the wording can change |
| `code` | A stable identifier, always present. Branch on this |
| `fields` | Present on a validation failure, keyed by the field at fault. Batch endpoints key by entry index instead. See [POST /sites/{siteId}/pages/batch](/api/pages/post-pages-batch) |

Some codes carry extra members: a `token_scope_required` refusal adds `scope`, a `site_limit_reached` 402 adds `limit` and `used`, a `domain_limit_reached` 402 adds those plus `includedDomains` and `domainPacks`, and a `pro_features_in_use` 402 adds `features`.

The codes you can branch on:

| Code | Meaning |
|------|---------|
| `bad_request` | The request could not be understood |
| `unauthorized` | Missing or invalid token |
| `forbidden` | The token may not do this |
| `token_scope_required` | The token lacks the scope named in `scope` |
| `payment_past_due` | The workspace's subscription needs attention |
| `plan_required` | The plan does not include this |
| `payment_required` | A 402 with no more specific code. The feature needs a plan you are not on |
| `quota_exceeded` | A storage or monthly quota is spent |
| `site_limit_reached` | The workspace is at its paid site capacity |
| `domain_limit_reached` | The workspace is at its paid custom-domain capacity |
| `pro_features_in_use` | The workspace is not on Pro but the site uses the Pro features in `features`, so it cannot be built |
| `not_found` | No such resource |
| `no_default_site` | The request named `default` but the workspace has no default site; name a site or set one |
| `method_not_allowed` | Wrong method; the `Allow` header lists the right ones |
| `not_acceptable` | No representation matches your `Accept` header |
| `conflict` | The request conflicts with the current state |
| `idempotency_key_reuse` | An `Idempotency-Key` was sent with a different request than the one it names |
| `idempotency_key_in_flight` | A request with this `Idempotency-Key` has not finished yet |
| `payload_too_large` | Body or file over the limit |
| `payload_field_too_large` | The multipart `payload` field is over its own 10 MB limit; split the batch rather than shrink the files |
| `unsupported_media_type` | The endpoint does not parse that `Content-Type` |
| `validation_failed` | The body parsed but does not validate; see `fields` |
| `cooldown_active` | The 30-second deploy cooldown is running |
| `rate_limited` | A rate limit, the upload budget, or the hourly deploy budget is spent |
| `internal_error` | Server error |
| `service_unavailable` | Server busy; retry shortly |

Wherever a request takes an `id`, a `siteId`, or any other resource ID, pass the ID a response gave you.

## Status codes

| Code | Meaning |
|------|---------|
| 200 | Success |
| 201 | Created. The `Location` header names the new resource, except on [POST /domains](/api/domains/post-domains) |
| 202 | Accepted: a deploy or preview build is queued. `Location` points at the status to poll |
| 204 | No content. Every write whose only news is that it worked answers this; a write that has something to report, such as the updated resource or a count of what it touched, answers 200 with it |
| 304 | Not modified. See [conditional reads](#conditional-reads) |
| 400 | The request could not be understood |
| 401 | Missing or invalid token |
| 402 | Quota exceeded, or the plan does not allow the operation |
| 403 | Pro plan required, the subscription is past due, or the token lacks the route's scope |
| 404 | Resource not found |
| 405 | Wrong method for this path; `Allow` lists the ones that work |
| 406 | No representation matches your `Accept` header |
| 409 | Conflicts with the current state (a taken slug, an only site, a domain already claimed, a per-site metadata cap reached, an `Idempotency-Key` still in flight) |
| 413 | Request body or file too large |
| 415 | The endpoint does not parse that `Content-Type` |
| 422 | The body parsed but a field is invalid; `fields` names them |
| 429 | Rate limit or deploy cooldown active |
| 500 | Server error |
| 503 | Server busy (retry shortly) |

400 and 422 divide this way: 400 means the request could not be understood, as with malformed JSON or a path that names no resource. 422 means it was understood and a field is wrong, and `fields` names them.

A `{siteId}` naming a site that does not exist, or one in another workspace, is a 404 on every route under `/sites/{siteId}`, never a 403.

An id that exists but belongs to another site of your own workspace is a 404 too: `/sites/a/previews/{id}` will not reach a preview that lives on site `b`.

## Paging

Every list takes the same two parameters:

| Parameter | Default | Meaning |
|-----------|---------|---------|
| `limit` | 1000 | How many to return, 1 to 1000 |
| `offset` | 0 | How many to skip |

and answers with the window plus the size of the whole collection:

```json
{
  "pages": [ ... ],
  "total": 4210,
  "limit": 100,
  "offset": 200
}
```

A `limit` or `offset` outside these ranges is a 422.

Every list is totally ordered, so walking one with `offset` visits each item exactly once, even straight after a batch write that touched many of them at once.

A few collections are bounded and are returned whole: sections and tags (capped per site), sites and domains (bounded by your plan), media folders, and active previews. These take no window, and answer a `limit` or `offset` with a 422.

## Idempotency

A POST that times out leaves you unable to tell whether it arrived. Send an `Idempotency-Key` and a retry is answered from the first request's recorded outcome instead of doing the work again.

```bash
KEY=$(uuidgen)
curl -X POST "https://sitepaste.com/api/v1/public/sites/default/deployments" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Idempotency-Key: $KEY"
# ... connection drops, outcome unknown. Send exactly the same request again:
curl -X POST "https://sitepaste.com/api/v1/public/sites/default/deployments" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Idempotency-Key: $KEY"
# HTTP/1.1 202 Accepted
# Idempotency-Replayed: true      <- one deploy was queued, not two
```

The key is yours to choose: any printable ASCII up to 255 characters, and a UUID is a good default. It is scoped to your workspace, so two workspaces using the same string never see each other's results, and it lasts 24 hours.

- A replayed response carries `Idempotency-Replayed: true` and repeats the original status, body, and `Location` exactly.
- The key remembers the whole request: method, path, query string, and body. Re-using one for a different request, including a retry with different `?` parameters, is a 422 with code `idempotency_key_reuse`.
- Query strings are compared in canonical form, which sorts parameters by name and keeps each name's own values in the order you sent them. So `?a=1&b=2` matches `?b=2&a=1`, while `?fileIds=a&fileIds=b` does not match `?fileIds=b&fileIds=a`. Send a repeated parameter's values in a stable order across a retry.
- A retry that arrives while the first request is still running gets a 409 with code `idempotency_key_in_flight` and a `Retry-After`. Wait that long and send it again.
- A keyed request has four minutes to finish and is cancelled if it runs longer, so a key always comes free for your retry. The one route that can approach that ceiling is [POST /uploads/{uploadId}/complete](/api/media/post-uploads-complete), which is safe to repeat without a key: a completion whose upload has already produced a file answers 409 naming that file.
- 5xx, 429, 402, and 409 release the key, so a retry genuinely retries. Every other status is kept: fix the body and use a new key.

Send it on anything unsafe. It is honoured on every POST, PATCH, and DELETE except the three routes that carry file uploads: [POST /media](/api/media/post-media), [POST /sites/{siteId}/pages](/api/pages/post-pages), and [POST /sites/{siteId}/pages/batch](/api/pages/post-pages-batch). Those refuse a supplied key with a 422 naming the header. Retry them without it: [POST /uploads](/api/media/post-uploads) keeps one handle however many times you retry the flow, the pages batch upserts by slug, and the single page create answers 409 on a page that already exists.

A key on a GET or HEAD is ignored, so a client that sets the header on every request is fine.

## Conditional reads

Every JSON read carries a strong `ETag` and honours `If-None-Match`:

```bash
# First read
curl -i "https://sitepaste.com/api/v1/public/sites/default/deployments/latest" \
  -H "Authorization: Bearer $TOKEN"
# ... ETag: "6b8c...":

# Poll without refetching the body
curl -i "https://sitepaste.com/api/v1/public/sites/default/deployments/latest" \
  -H "Authorization: Bearer $TOKEN" \
  -H 'If-None-Match: "6b8c..."'
# HTTP/1.1 304 Not Modified
```

Send the `ETag` back and an unchanged resource answers 304 with no body, which keeps polling a deploy cheap. Reads carry `Cache-Control: private, no-cache`: store the response, and revalidate before using it.

The zip and CSV representations above carry no validator, so a conditional request for one is served in full.

## Deleting in a batch

Three endpoints delete alongside their writes, and they differ in what an entry that matches nothing does:

| Endpoint | Field | An entry that matches nothing |
|----------|-------|-------------------------------|
| [POST /sites/{siteId}/pages/batch](/api/pages/post-pages-batch) | `deleteSlugs` | Ignored. The response's `deleted` lists only what was actually removed |
| [POST /sites/{siteId}/event-types/batch](/api/events/post-event-types-batch) | `deleteSlugs` | Ignored. The response's `deleted` lists only what was actually removed |
| [POST /sites/{siteId}/events/batch](/api/events/post-events-batch) | `deleteIds` | Rejected with 422, and nothing in the batch is written |

The single-resource deletes answer 404 when the target does not exist. That covers every DELETE on an item URI, from `/sites/{siteId}/pages/{contentType}/{slug}` through the media, domain, and subscriber routes.

Tags are the exception. [DELETE /sites/{siteId}/tags/{slug}](/api/tags/delete-tags-slug) always answers 200 with the number of pages the tag was removed from, so a tag no page carries comes back as `{"deleted": 0}` rather than a 404. [PATCH /sites/{siteId}/tags/{slug}](/api/tags/patch-tags-slug) answers 200 with the tag as it now stands, adding a `renamed` count when the request renamed it.

## Rate limiting

Three budgets apply, and one request can spend more than one of them.

| Budget | Limit | Counted per | Spent by |
|---|---|---|---|
| Requests | 600 per minute | Calling client | Every request |
| Uploads | 600 per minute | Workspace | [POST /media](/api/media/post-media) and [POST /uploads/{uploadId}/complete](/api/media/post-uploads-complete) |
| Deploys | 300 per hour | Workspace | [POST /sites/{siteId}/deployments](/api/deployments/post-deployments), [POST /sites/{siteId}/previews](/api/previews/post-previews), [rebuild](/api/previews/post-previews-rebuild), [promote](/api/previews/post-previews-promote), and [GET /sites/{siteId}/pages](/api/pages/get-pages) asked for as `application/zip` |

The request budget is counted per calling client, not per token or
workspace. The other two budgets are shared by every token in a workspace.

A [batch](/api/pages/post-pages-batch) is one request whether it carries 1 page
or 5,000, and neither it nor its inline media spends anything from the deploy
budget. Write in bulk, then deploy once. The
[30-second deploy cooldown](/api/deployments/post-deployments) is usually the
tighter limit, since it caps a site at 120 deploys an hour on its own.

Work refused before it starts costs nothing, so retrying into a cooldown cannot
drain the hour. [POST /media](/api/media/post-media) is the exception: it
spends from the upload budget as soon as the request arrives.

A spent budget answers 429 with `Retry-After` in seconds. A refused deploy
leaves your writes saved.

| Refused by | `Retry-After` |
|---|---|
| A per-minute budget | 60 |
| The hourly deploy budget | 3600 |
| The 30-second deploy cooldown | The seconds left on it, rounded up |

Each budget reports under its own headers:

| Headers | Budget |
|---|---|
| `X-RateLimit-Limit`, `X-RateLimit-Remaining` | Requests |
| `X-Upload-RateLimit-Limit`, `X-Upload-RateLimit-Remaining` | Uploads |
| `X-Heavy-RateLimit-Limit`, `X-Heavy-RateLimit-Remaining` | Deploys |

The upload and deploy pairs are sent on a request that goes through as well as
on one that is refused, so a job can pace itself against what is left. A
response can omit a `-Remaining` header. Treat its absence as no news rather
than as a spent budget.

For publishing without writing code, see the [Publish from guides](/guides/publish-from/) for the Obsidian plugin, the GitHub Action, and Apple Shortcuts.