# Server API

Accounts, sync, sharing and published sites. Every call is JSON unless it says otherwise, and errors answer `{ message, code? }` with a message written for people.

## Base URL

```text
https://your-hatch-server
```

## Authentication

- **session**: send `Authorization: Bearer <token>`. The session token from signing in (or the session cookie in a browser on the same origin).

## Endpoints

### Account

| Endpoint | What it does |
| --- | --- |
| `GET /api/me` | [Who is signed in](https://hatch-docs.pages.dev/api-reference/account/me/) |
| `GET /api/sessions` | [Where this account is signed in. Ids only: a session’s token never leaves the server.](https://hatch-docs.pages.dev/api-reference/account/sessions/) |
| `DELETE /api/sessions/{session}` | [Sign out one of this account’s sessions](https://hatch-docs.pages.dev/api-reference/account/sign-out-session/) |
| `POST /api/sessions/confirm` | [Confirm the password before adding a passkey. Lasts 10 minutes for this session.](https://hatch-docs.pages.dev/api-reference/account/confirm-password/) |
| `GET /api/ai-keys` | [Whether this account keeps AI keys (the person turns it on), and the keys. Sealed on the server; only this account’s own sessions get them.](https://hatch-docs.pages.dev/api-reference/account/ai-keys/) |
| `PUT /api/ai-keys` | [Turn keeping AI keys in this account on or off. Off deletes the keys it kept.](https://hatch-docs.pages.dev/api-reference/account/keep-ai-keys/) |
| `PUT /api/ai-keys/{name}` | [Keep an AI key (anthropic or openai) in this account, sealed at rest. Refused while keeping keys is off.](https://hatch-docs.pages.dev/api-reference/account/set-ai-key/) |
| `DELETE /api/ai-keys/{name}` | [Take an AI key out of this account](https://hatch-docs.pages.dev/api-reference/account/remove-ai-key/) |
| `GET /api/account/export` | [Download everything the server keeps about you](https://hatch-docs.pages.dev/api-reference/account/export/) |
| `POST /api/sso/exchange` | [Trade the one-time code from a single sign-on for a session. The answer’s set-auth-token header holds the token.](https://hatch-docs.pages.dev/api-reference/account/sso-exchange/) |

### Billing

| Endpoint | What it does |
| --- | --- |
| `GET /api/billing` | [Your plan, and the plans there are](https://hatch-docs.pages.dev/api-reference/billing/get/) |
| `POST /api/billing/checkout` | [Start paying for a plan](https://hatch-docs.pages.dev/api-reference/billing/checkout/) |
| `POST /api/billing/portal` | [Open the billing portal](https://hatch-docs.pages.dev/api-reference/billing/portal/) |

### Sites

| Endpoint | What it does |
| --- | --- |
| `GET /api/sites` | [Your sites, and what this server can do for them](https://hatch-docs.pages.dev/api-reference/sites/list/) |
| `POST /api/sites` | [Make a site](https://hatch-docs.pages.dev/api-reference/sites/create/) |
| `PATCH /api/sites/{id}` | [Change a site’s title, who can see it, or its invites](https://hatch-docs.pages.dev/api-reference/sites/update/) |
| `DELETE /api/sites/{id}` | [Delete a site](https://hatch-docs.pages.dev/api-reference/sites/delete/) |
| `PUT /api/sites/{id}/deploy` | [Publish a built site](https://hatch-docs.pages.dev/api-reference/sites/deploy/) |
| `GET /api/sites/{id}/activity` | [What happened to a site, newest first](https://hatch-docs.pages.dev/api-reference/sites/activity/) |
| `PATCH /api/sites/{id}/vault` | [Link a site to a synced vault, or unlink it](https://hatch-docs.pages.dev/api-reference/sites/vault/) |
| `GET /api/sites/{id}/notifications` | [How the owner hears about new responses](https://hatch-docs.pages.dev/api-reference/sites/notify-get/) |
| `PUT /api/sites/{id}/notifications` | [Change how the owner hears about new responses](https://hatch-docs.pages.dev/api-reference/sites/notify-set/) |

### Analytics

| Endpoint | What it does |
| --- | --- |
| `GET /api/sites/{id}/stats` | [Visits to a site](https://hatch-docs.pages.dev/api-reference/analytics/sites-stats/) |

### Roadmap

| Endpoint | What it does |
| --- | --- |
| `GET /api/sites/{id}/votes` | [Votes for each roadmap item](https://hatch-docs.pages.dev/api-reference/roadmap/sites-votes/) |

### Domains

| Endpoint | What it does |
| --- | --- |
| `GET /api/sites/{id}/domain` | [A site’s own domain and the DNS records it needs](https://hatch-docs.pages.dev/api-reference/domains/get/) |
| `PUT /api/sites/{id}/domain` | [Give a site its own domain](https://hatch-docs.pages.dev/api-reference/domains/set/) |
| `DELETE /api/sites/{id}/domain` | [Stop using a site’s own domain](https://hatch-docs.pages.dev/api-reference/domains/remove/) |
| `POST /api/sites/{id}/domain/check` | [Check a domain’s DNS records again](https://hatch-docs.pages.dev/api-reference/domains/check/) |

### Newsletter

| Endpoint | What it does |
| --- | --- |
| `GET /api/sites/{id}/newsletter` | [A site’s subscribers and the issues it sent](https://hatch-docs.pages.dev/api-reference/newsletter/get/) |
| `DELETE /api/sites/{id}/subscribers/{sid}` | [Remove a subscriber](https://hatch-docs.pages.dev/api-reference/newsletter/remove-subscriber/) |
| `POST /api/sites/{id}/issues` | [Email a page to subscribers, or a test to yourself](https://hatch-docs.pages.dev/api-reference/newsletter/send/) |

### Forms

| Endpoint | What it does |
| --- | --- |
| `GET /api/sites/{id}/submissions` | [Responses to a site’s forms](https://hatch-docs.pages.dev/api-reference/forms/list/) |
| `DELETE /api/sites/{id}/submissions/{sid}` | [Delete a form response](https://hatch-docs.pages.dev/api-reference/forms/remove/) |
| `GET /api/sites/{id}/webhook` | [A site’s form webhook, with its secret](https://hatch-docs.pages.dev/api-reference/forms/webhook/) |
| `PUT /api/sites/{id}/webhook` | [Send new form responses to an address](https://hatch-docs.pages.dev/api-reference/forms/set-webhook/) |
| `DELETE /api/sites/{id}/webhook` | [Stop sending form responses](https://hatch-docs.pages.dev/api-reference/forms/remove-webhook/) |
| `POST /api/sites/{id}/webhook/test` | [Send a made-up response to the webhook now](https://hatch-docs.pages.dev/api-reference/forms/test-webhook/) |

### Careers

| Endpoint | What it does |
| --- | --- |
| `GET /api/sites/{id}/applications` | [Applications to a careers site](https://hatch-docs.pages.dev/api-reference/careers/list/) |
| `GET /api/sites/{id}/applications/{aid}/resume` | [Download an applicant’s resume](https://hatch-docs.pages.dev/api-reference/careers/resume/) |
| `DELETE /api/sites/{id}/applications/{aid}` | [Delete an application](https://hatch-docs.pages.dev/api-reference/careers/remove/) |
| `GET /api/sync/vaults/{vault}/careers` | [The careers site a vault is linked to](https://hatch-docs.pages.dev/api-reference/careers/for-vault/) |

### Sync

| Endpoint | What it does |
| --- | --- |
| `GET /api/sync/vaults` | [Your synced vaults, and ones shared with you](https://hatch-docs.pages.dev/api-reference/sync/vaults-list/) |
| `POST /api/sync/vaults` | [Start syncing a vault](https://hatch-docs.pages.dev/api-reference/sync/vaults-create/) |
| `PATCH /api/sync/vaults/{vault}/name` | [Rename a vault](https://hatch-docs.pages.dev/api-reference/sync/vaults-rename/) |
| `DELETE /api/sync/vaults/{vault}` | [Delete a vault from the server, or leave one shared with you](https://hatch-docs.pages.dev/api-reference/sync/vaults-delete/) |
| `GET /api/sync/vaults/{vault}/activity` | [What happened in a vault, newest first](https://hatch-docs.pages.dev/api-reference/sync/vaults-activity/) |
| `GET /api/sync/vaults/{vault}/changes` | [Files changed since a revision](https://hatch-docs.pages.dev/api-reference/sync/vaults-changes/) |
| `GET /api/sync/vaults/{vault}/file` | [A file’s bytes](https://hatch-docs.pages.dev/api-reference/sync/vaults-read-file/) |
| `PUT /api/sync/vaults/{vault}/file` | [Save a file](https://hatch-docs.pages.dev/api-reference/sync/vaults-write-file/) |
| `DELETE /api/sync/vaults/{vault}/file` | [Delete a file](https://hatch-docs.pages.dev/api-reference/sync/vaults-delete-file/) |
| `GET /api/sync/vaults/{vault}/versions` | [A file’s history, newest first](https://hatch-docs.pages.dev/api-reference/sync/vaults-versions/) |
| `GET /api/sync/vaults/{vault}/version` | [One older version’s bytes](https://hatch-docs.pages.dev/api-reference/sync/vaults-version/) |

### Sharing

| Endpoint | What it does |
| --- | --- |
| `GET /api/sync/vaults/{vault}/people` | [Who a vault is shared with, and open invites](https://hatch-docs.pages.dev/api-reference/sharing/people/) |
| `POST /api/sync/vaults/{vault}/invites` | [Invite someone to a vault by email](https://hatch-docs.pages.dev/api-reference/sharing/invite/) |
| `PUT /api/sync/vaults/{vault}/people/{user}/role` | [Change what someone a vault is shared with may do](https://hatch-docs.pages.dev/api-reference/sharing/set-role/) |
| `GET /api/sync/vaults/{vault}/rules` | [Folder rules: who may do what in which folder](https://hatch-docs.pages.dev/api-reference/sharing/rules/) |
| `PUT /api/sync/vaults/{vault}/rules` | [Give someone, or everyone, a role in one folder](https://hatch-docs.pages.dev/api-reference/sharing/set-rule/) |
| `POST /api/sync/vaults/{vault}/rules/move` | [A folder was renamed or moved: its rules go with it](https://hatch-docs.pages.dev/api-reference/sharing/move-rules/) |
| `DELETE /api/sync/vaults/{vault}/invites/{invite}` | [Cancel an invite](https://hatch-docs.pages.dev/api-reference/sharing/cancel-invite/) |
| `DELETE /api/sync/vaults/{vault}/people/{user}` | [Remove someone from a vault, or leave it](https://hatch-docs.pages.dev/api-reference/sharing/remove/) |
| `GET /api/sync/invites` | [Invites waiting for you](https://hatch-docs.pages.dev/api-reference/sharing/my-invites/) |
| `POST /api/sync/invites/{invite}/accept` | [Join a vault you were invited to](https://hatch-docs.pages.dev/api-reference/sharing/accept/) |
| `POST /api/sync/invites/{invite}/decline` | [Turn an invite down](https://hatch-docs.pages.dev/api-reference/sharing/decline/) |

### Workspaces

| Endpoint | What it does |
| --- | --- |
| `GET /api/workspace-invites` | [Invites to workspaces waiting for this account. Shown once its address is confirmed, when the server can confirm addresses.](https://hatch-docs.pages.dev/api-reference/workspaces/invites/) |
| `GET /api/workspaces/{workspace}` | [A workspace’s rules, email domains and vaults. Members only; admins also see the records to add.](https://hatch-docs.pages.dev/api-reference/workspaces/get/) |
| `PATCH /api/workspaces/{workspace}` | [Change a workspace’s rules. Owners and admins.](https://hatch-docs.pages.dev/api-reference/workspaces/update/) |
| `POST /api/workspaces/{workspace}/domains` | [Start proving the workspace owns an email domain. Answers the TXT record to add.](https://hatch-docs.pages.dev/api-reference/workspaces/domains-add/) |
| `POST /api/workspaces/{workspace}/domains/{domain}/verify` | [Check the domain’s TXT record](https://hatch-docs.pages.dev/api-reference/workspaces/domains-verify/) |
| `DELETE /api/workspaces/{workspace}/domains/{domain}` | [Stop using an email domain](https://hatch-docs.pages.dev/api-reference/workspaces/domains-remove/) |
| `GET /api/workspaces/{workspace}/sso` | [The workspace’s single sign-on, and the addresses to give its identity provider. Owners and admins.](https://hatch-docs.pages.dev/api-reference/workspaces/sso-get/) |
| `PUT /api/workspaces/{workspace}/sso` | [Set up or replace single sign-on for a verified domain. Owners, after entering their password.](https://hatch-docs.pages.dev/api-reference/workspaces/sso-set/) |
| `PATCH /api/workspaces/{workspace}/sso` | [Make single sign-on the only way in for members in the domain. Owners who have signed in with it.](https://hatch-docs.pages.dev/api-reference/workspaces/sso-only/) |
| `DELETE /api/workspaces/{workspace}/sso` | [Turn single sign-on off. Owners, after entering their password.](https://hatch-docs.pages.dev/api-reference/workspaces/sso-remove/) |
| `GET /api/workspaces/{workspace}/scim` | [Whether the workspace’s directory provisions its people (SCIM), and the address to give it. Owners and admins.](https://hatch-docs.pages.dev/api-reference/workspaces/scim-get/) |
| `POST /api/workspaces/{workspace}/scim` | [Make the directory’s bearer token, replacing any old one. Shown once. Owners, after entering their password.](https://hatch-docs.pages.dev/api-reference/workspaces/scim-token/) |
| `DELETE /api/workspaces/{workspace}/scim` | [Stop the directory provisioning people. Those it added stay. Owners, after entering their password.](https://hatch-docs.pages.dev/api-reference/workspaces/scim-remove/) |
| `GET /api/workspaces/{workspace}/activity` | [Who joined, left, signed in and changed roles, and every change to the rules, newest first. Owners and admins.](https://hatch-docs.pages.dev/api-reference/workspaces/activity/) |
| `GET /api/workspaces/{workspace}/activity/export` | [Download the workspace’s activity as CSV or JSON, with the same filters, up to 50,000 events. Owners and admins.](https://hatch-docs.pages.dev/api-reference/workspaces/activity-export/) |
| `GET /api/workspaces/{workspace}/stream` | [Where the workspace’s activity is sent as it happens (to a SIEM), if anywhere. Owners and admins; admins see only its origin.](https://hatch-docs.pages.dev/api-reference/workspaces/stream-get/) |
| `PUT /api/workspaces/{workspace}/stream` | [Send each new activity event to this https address, signed like form webhooks. The signing secret is in the answer only when it’s new. Owners, after entering their password.](https://hatch-docs.pages.dev/api-reference/workspaces/stream-set/) |
| `DELETE /api/workspaces/{workspace}/stream` | [Stop sending activity. Owners, after entering their password.](https://hatch-docs.pages.dev/api-reference/workspaces/stream-remove/) |
| `POST /api/workspaces/{workspace}/stream/test` | [Send a test event now. Owners and admins.](https://hatch-docs.pages.dev/api-reference/workspaces/stream-test/) |
| `PUT /api/sync/vaults/{vault}/workspace` | [Share a vault you made with a workspace you manage, or take it back (workspace: null)](https://hatch-docs.pages.dev/api-reference/workspaces/vaults-workspace/) |

### Live editing

| Endpoint | What it does |
| --- | --- |
| `POST /api/live/ticket` | [A one-time ticket to open a live editing connection](https://hatch-docs.pages.dev/api-reference/live-editing/live-ticket/) |
