# Patch API

Create captures in Patch from anywhere, without opening the app: a script, a
Figma plugin, a GitHub workflow, or an AI agent.

Two endpoints, both plain HTTPS + JSON. No SDK needed. Using an MCP-capable
AI client instead? Skip to [MCP](#mcp).

## Use with an AI agent

Your agent needs **both** of the following. The docs link alone is not enough.

**1. API reference URL.** Paste into your agent's instructions or docs field
(you don't need to open it in a browser):

```text
https://app.getpatchapp.com/docs/api.md
```

**2. Personal access token.** [Generate one in Patch](https://app.getpatchapp.com/access-tokens),
copy it once, and tell your agent to send `Authorization: Bearer patch_pat_…` on
every request. Treat the token like a password.

| Endpoint | What it does |
| --- | --- |
| `GET /api/v1/list-projects` | Your projects, so a caller can pick where a capture goes |
| `POST /api/v1/create-capture` | Create a capture (a note, an image, or both) in a project |

## Base URL

```text
https://app.getpatchapp.com/api/v1
```

## Authentication

Every request needs a personal access token in the `Authorization` header:

```text
Authorization: Bearer patch_pat_…
```

Generate one at [app.getpatchapp.com/access-tokens](https://app.getpatchapp.com/access-tokens).
Tokens are shown once at creation; you choose their expiry (7 days to never).
A token acts as you, so it can only see and write to your own projects.

`create-capture` takes a JSON body, so send `Content-Type: application/json`
with it.

## List projects

`GET /api/v1/list-projects`

No parameters.

```bash
curl https://app.getpatchapp.com/api/v1/list-projects \
  -H "Authorization: Bearer patch_pat_…"
```

Response `200`: a JSON array, newest project first.

```json
[
  { "id": "2b6c1c9e-…", "name": "Checkout redesign", "status": "active" },
  { "id": "9f0a4d21-…", "name": "Onboarding v2",     "status": "done" }
]
```

`status` is one of `active`, `paused`, `done`.

There is no default project. Call this first, pick (or ask the user to pick)
a project, then pass its `id` to `create-capture`.

## Create capture

`POST /api/v1/create-capture`

Body:

| Field | Type | Required | Notes |
| --- | --- | --- | --- |
| `project_id` | string (UUID) | yes | From `list-projects`. Must be your own project. |
| `note` | string | one of `note` / image | What happened. First line becomes the capture's title unless you set one (see below). |
| `title` | string | no | Your own title, at most 80 characters (a commit subject, a frame name). Leave it out or empty and Patch derives one. A title alone isn't a capture. You still need a `note` or an image. |
| `image_url` | string | one of `note` / image | An `https` URL to an image already hosted somewhere (a Figma export, a GitHub attachment). Patch fetches it and stores its own copy. |
| `image_base64` | string | one of `note` / image | Raw base64 of an image file (no `data:` prefix). Use this for a file on the caller's machine or a pasted screenshot. |
| `image_mime_type` | string | with `image_base64` | The image's media type, e.g. `image/png`. |

A capture needs a non-empty `note`, an image, or both. Send **either**
`image_url` **or** `image_base64`, not both.

Note-only:

```bash
curl -X POST https://app.getpatchapp.com/api/v1/create-capture \
  -H "Authorization: Bearer patch_pat_…" \
  -H "Content-Type: application/json" \
  -d '{
    "project_id": "2b6c1c9e-…",
    "note": "Shipped the new checkout flow\nConversion is up 12% on the first day."
  }'
```

Hosted image:

```bash
curl -X POST https://app.getpatchapp.com/api/v1/create-capture \
  -H "Authorization: Bearer patch_pat_…" \
  -H "Content-Type: application/json" \
  -d '{
    "project_id": "2b6c1c9e-…",
    "note": "Final checkout layout",
    "image_url": "https://example.com/exports/checkout-final.png"
  }'
```

Local file:

```bash
curl -X POST https://app.getpatchapp.com/api/v1/create-capture \
  -H "Authorization: Bearer patch_pat_…" \
  -H "Content-Type: application/json" \
  -d "{
    \"project_id\": \"2b6c1c9e-…\",
    \"image_base64\": \"$(base64 -w0 screenshot.png)\",
    \"image_mime_type\": \"image/png\"
  }"
```

Response `200`:

```json
{
  "id": "6d3f8a10-…",
  "title": "Shipped the new checkout flow",
  "type": "milestone",
  "project_id": "2b6c1c9e-…"
}
```

### Title and type

- **Title**: `title` if you sent one. Otherwise derived the same way the app
  does it: the first non-empty line of `note`, trimmed, at most 80
  characters; for an image-only capture, the image's filename (or
  `capture.png` etc. for `image_base64`).
- **Type**: not a request field. It's inferred from `note` by keyword: `result` (a percentage, or
  words like *increased*, *dropped*, *grew*, *reached*), `milestone`
  (*shipped*, *launched*, *merged*, *released*, *deployed*), `decision`
  (*went with*, *chose*, *decided*, *instead of*), otherwise `note`. Image-only
  captures are `note`.

Write the note the way you'd tell a teammate what happened and the type will
usually come out right.

### Image rules

These apply to the API only (the Patch app itself accepts larger files).

- **Size**: up to **5 MB**, measured on the actual image bytes (after base64
  decoding, or as fetched from `image_url`).
- **Types**: `image/png`, `image/jpeg`, `image/gif`, `image/webp`.
- **`image_url`** must be `https`, and the response must carry one of the
  types above in its `Content-Type`. The URL is fetched once and never
  stored. Patch keeps its own copy.
- **`image_base64`** is plain base64 (whitespace is fine, a `data:` prefix
  is not). Base64 inflates the payload by ~33%, so a 5 MB image is a ~6.7 MB
  request body.

## Rate limit

**30 requests per minute per token**, across both endpoints, in a fixed
60-second window that starts with the first request. Over the limit you get
`429` with a `Retry-After` header (seconds until the window resets).

If you're creating captures in a batch (say, one per commit), either pace to
under 30/min or back off on `429` for `Retry-After` seconds. A second token
gets its own limit.

## Errors

All errors are JSON: `{ "error": "message" }`.

| Status | When |
| --- | --- |
| `400` | Invalid JSON body; `project_id` missing or not a UUID; neither `note` nor an image given; `title` over 80 characters; both `image_url` and `image_base64` given; `image_url` not `https` or not fetchable; image type not allowed; image over 5 MB; `image_base64` not valid base64 or missing `image_mime_type`. The message says which. |
| `401` | `Authorization` header missing or malformed, or the token is unknown, revoked or expired (the message is the same for all three). |
| `404` | `project_id` doesn't belong to you, including ids that exist under another account. |
| `405` | Wrong method. `list-projects` is `GET`, `create-capture` is `POST`. |
| `429` | Rate limit exceeded. See `Retry-After`. |
| `500` | Something went wrong on our side. Safe to retry. |

Examples:

```json
{ "error": "A capture needs a note or an image" }
{ "error": "Image exceeds the 5 MB limit for the API. Larger files can be added from the Patch app." }
{ "error": "Invalid or expired token" }
{ "error": "Project not found" }
{ "error": "Rate limit exceeded: 30 requests per minute per token" }
```

## MCP

If you use an AI client that speaks [MCP](https://modelcontextprotocol.io)
(Claude Desktop, Claude Code, Cursor, and others), you don't need the REST
endpoints at all. Connect the client to Patch's MCP server and it gets the
same two operations as tools, `list_projects` and `create_capture`, with the
same arguments and rules described above.

```text
https://app.getpatchapp.com/api/v1/mcp
```

Same token, same header: `Authorization: Bearer patch_pat_…`. Transport is
Streamable HTTP; there's nothing to run locally.

Most clients take a remote server as a URL plus headers. The shape is
usually:

```json
{
  "mcpServers": {
    "patch": {
      "url": "https://app.getpatchapp.com/api/v1/mcp",
      "headers": { "Authorization": "Bearer patch_pat_…" }
    }
  }
}
```

If your client can't send custom headers to a remote server, bridge it with
[`mcp-remote`](https://www.npmjs.com/package/mcp-remote):
`npx mcp-remote https://app.getpatchapp.com/api/v1/mcp --header "Authorization: Bearer patch_pat_…"`.

Tool calls draw from the same 30 requests/minute as the REST endpoints;
the handshake (`initialize`, `tools/list`) doesn't count.

## For AI agents

Whether you're calling REST or MCP: list the projects first, show the user
their projects and confirm which one the capture should go to before
creating it. Don't guess: there is no default project.
