# Files and notes

Read, search, save and download the notes and files in a Space.

Web version: https://www.svanja.com/docs/api/files/

Every Space in [Spaces](https://app.svanja.com/spaces) holds your notes and files, and these endpoints let you work with them. A note is a Markdown text file. You can read what you keep about a client, search through it, or save a note from your own tool.

To read files, your key needs the Spaces and files area, which Full access and Read-only both include. To save changes, it needs Full access or Spaces and files set to **Read and write**. If a key is limited to certain Spaces, it can only reach the files inside them. For more on how Spaces work, see [Spaces, notes and files](https://www.svanja.com/docs/spaces/).

Everything inside a Space lives under `/spaces/{space}/files`. From there, you can list and search files, read a file along with its `revision`, view its history, or download it.

Use `PUT /spaces/{space}/files/content` to save a note or any other text file. Send `path`, `content`, and `expected_revision` (the revision you got when you read the file). If someone else changed the file in the meantime, the save fails with `conflict` so you don't overwrite their work. When creating a new file, set `expected_revision` to `null`.

```json
{
  "path": "notes/status.md",
  "content": "Export fixed, waiting for the client's OK.",
  "expected_revision": "REVISION_FROM_THE_READ"
}
```

Saved changes show up in the Space's history like any other edit, with the key's owner listed as the author. If you prefer working from a terminal, see [svanja notes and svanja files](https://www.svanja.com/docs/cli/notes-and-files/).

## Operations

| Operation | What it does | Effect | Endpoints |
| --- | --- | --- | --- |
| `file.download` | Download a Space file. | Reads only | `GET /spaces/{space}/files/download` |
| `file.read` | Read Space files and history. | Reads only | `GET /spaces/{space}/files`<br>`GET /spaces/{space}/files/content`<br>`GET /spaces/{space}/files/history`<br>`GET /spaces/{space}/files/search` |
| `file.save` | Save a Space file revision. | Changes data in Svanja | `PUT /spaces/{space}/files/content` |

## Endpoints

### GET /api/v1/spaces/{space}/files

List Space files

Lists current source entries and knowledge pins inside an accessible Space.

| Parameter | In | Type | Required | Notes |
| --- | --- | --- | --- | --- |
| `space` | path | string | yes | Space public ULID or slug. |

### GET /api/v1/spaces/{space}/files/content

Read a Space file

Reads the current content of one source file after current access checks.

| Parameter | In | Type | Required | Notes |
| --- | --- | --- | --- | --- |
| `space` | path | string | yes | Space public ULID or slug. |
| `path` | query | string | yes |  |

### PUT /api/v1/spaces/{space}/files/content

Save a Space file

Saves source content with optional revision conflict detection.

| Parameter | In | Type | Required | Notes |
| --- | --- | --- | --- | --- |
| `space` | path | string | yes | Space public ULID or slug. |
| `Idempotency-Key` | header | string | no | Optional key for unsafe bearer writes. Reusing the same key and same canonical body replays the original response for 24 hours; reusing it with a different body returns idempotency_conflict. |

| Body field | Type | Required | Notes |
| --- | --- | --- | --- |
| `path` | string | yes |  |
| `content` | string | yes |  |
| `expected_revision` | string or null | no |  |

### GET /api/v1/spaces/{space}/files/history

Read Space file history

| Parameter | In | Type | Required | Notes |
| --- | --- | --- | --- | --- |
| `space` | path | string | yes | Space public ULID or slug. |
| `path` | query | string | no |  |
| `commit` | query | string | no |  |
| `limit` | query | integer | no |  |

### GET /api/v1/spaces/{space}/files/search

Search Space files

| Parameter | In | Type | Required | Notes |
| --- | --- | --- | --- | --- |
| `space` | path | string | yes | Space public ULID or slug. |
| `q` | query | string | yes |  |
| `limit` | query | integer | no |  |

### GET /api/v1/spaces/{space}/files/download

Download a Space file

Streams a bearer-authorized source or binary object after current access checks.

| Parameter | In | Type | Required | Notes |
| --- | --- | --- | --- | --- |
| `space` | path | string | yes | Space public ULID or slug. |
| `path` | query | string | yes |  |
| `commit` | query | string | no |  |
| `object_id` | query | string | no |  |
