# API

Use the HTTP API to read, search and change your files. API keys need
[Pro](/docs/plans). The [OpenAPI reference](https://memomori.app/api/v1/openapi.json) lists
every route a key can call, with its parameters and responses.

## Get a key

1. Open [Settings → Integrations](https://memomori.app/settings/integrations) and click
   **Create** under API keys.
2. Name it and pick `read`, `write` or both. Use `read` for scripts that only
   fetch files.
3. Pick an expiry, from 7 days to never.
4. Copy the key. MemoMori shows it only once.

Set `MEMOMORI_KEY` in your shell and send it in the `Authorization` header.
Keep it out of source control. An account can hold up to 25 keys; delete one
in Settings → Integrations to revoke it.

Keys cannot manage credentials, sessions, settings, billing or the account.
Do that in the app.

## Examples

These commands use curl. Replace paths and text with your own. Paths start
at the top of your files and have no leading `/`.

### Read a note

```sh
curl --fail-with-body --get \
  -H "Authorization: Bearer $MEMOMORI_KEY" \
  --data-urlencode 'path=plans.md' \
  'https://memomori.app/api/v1/entries/content'
```

This route returns raw text. Most other routes return JSON under `data`.

### Create or replace a note

```sh
curl --fail-with-body -X PUT \
  -H "Authorization: Bearer $MEMOMORI_KEY" \
  -H 'Content-Type: text/plain; charset=utf-8' \
  --data-binary @plans.md \
  'https://memomori.app/api/v1/entries/content?path=plans.md'
```

`PUT` replaces the whole note. Read it first and send its `ETag` in an
`If-Match` header when you need to protect someone else's edits.

### Append to a journal

```sh
printf '%s\n' '- Finished the draft' | \
  curl --fail-with-body \
    -H "Authorization: Bearer $MEMOMORI_KEY" \
    -H 'Content-Type: text/plain; charset=utf-8' \
    --data-binary @- \
    "https://memomori.app/api/v1/entries/content?path=journal/$(date +%F).md"
```

`POST` appends text, or creates the note if it is missing. It does not add a
newline for you.

### Change part of a note

```sh
curl --fail-with-body -X PATCH \
  -H "Authorization: Bearer $MEMOMORI_KEY" \
  --json '{"edits":[{"old":"Status: draft","new":"Status: ready"}]}' \
  'https://memomori.app/api/v1/entries/content?path=plans.md'
```

`old` must match exactly once unless you set `replace_all: true`. The edits
apply in order; if any fails, none save.

### Save an article

```sh
curl --fail-with-body \
  -H "Authorization: Bearer $MEMOMORI_KEY" \
  --json '{"url":"https://go.dev/blog/errors-are-values","parent":"reading"}' \
  'https://memomori.app/api/v1/entries/clip'
```

### Search note content

```sh
curl --fail-with-body --get \
  -H "Authorization: Bearer $MEMOMORI_KEY" \
  --data-urlencode 'q=invoice' \
  --data-urlencode 'match=content' \
  'https://memomori.app/api/v1/entries'
```

Lists return `page.has_more` and `page.next_cursor`. Pass the cursor as
`cursor` to read the next page. Check `page.partial` before treating a search
as complete.

## Handle errors and retries

Errors return an `error` object with `code` and `message`.

| Status | What to do                                                                         |
| ------ | ---------------------------------------------------------------------------------- |
| `401`  | Check that the key is valid and has not expired                                    |
| `402`  | Check that Pro is active                                                           |
| `403`  | Check the key's scopes                                                             |
| `412`  | Read the file again; it changed since your `If-Match` value                        |
| `422`  | Check the error code and field errors; the input or storage limit may be the cause |
| `429`  | Slow down; follow `Retry-After` when present                                       |

Use `If-Match` to guard updates. Use `Idempotency-Key` on supported mutations
to retry the same request without repeating it. Keep the key and body the
same across retries. Give each separate action a new key.

## Reference

- [OpenAPI](https://memomori.app/api/v1/openapi.json): routes, schemas and authentication rules.
- [API discovery](https://memomori.app/api/v1): live request and response limits; requires a key.
- [llms.txt](https://memomori.app/llms.txt): API guide for agents.
- [MCP](/docs/mcp): connect a client without writing HTTP requests.
