# Documents API

> Files and links on records: upload, download, link. Every route, its parameters and fields.

Files and links on records: upload, download, link. 13 routes; send a bearer token with each (see [Authentication](/api/authentication.md)).

| Route | What it does |
| --- | --- |
| `GET /v1/documents` | List documents |
| `POST /v1/documents` | Add a link to a file (SharePoint, OneDrive or other https) |
| `GET /v1/documents/{id}` | Get a document |
| `PATCH /v1/documents/{id}` | Rename a document |
| `DELETE /v1/documents/{id}` | Delete a document (soft delete) |
| `POST /v1/documents/upload` | Upload a file (paid plans) |
| `POST /v1/documents/import` | Attach a file from an https URL or base64 content (paid plans) |
| `POST /v1/documents/{id}/restore` | Restore a deleted document |
| `POST /v1/documents/{id}/links/{type}/{recordId}` | Link a document to another record |
| `DELETE /v1/documents/{id}/links/{type}/{recordId}` | Unlink a document from a record |
| `GET /v1/documents/{id}/content` | Download a file |
| `POST /v1/documents/{id}/signed-link` | A 15-minute download link |
| `GET /v1/files/{token}` | Download through a signed link |

## List documents

`GET https://staging-api.naruskacrm.com/v1/documents`

Documents you can see, newest first; filter by a linked record (contact_id, account_id, opportunity_id, quote_id, case_id), kind or name (`q`).

### Parameters

| Parameter | In | Type | Required | Notes |
| --- | --- | --- | --- | --- |
| `limit` | query | integer |  | 1–200, default `50` |
| `cursor` | query | string |  | next_cursor of the previous page. 1–400 characters |
| `contact_id` | query | string (uuid) |  |  |
| `account_id` | query | string (uuid) |  |  |
| `opportunity_id` | query | string (uuid) |  |  |
| `quote_id` | query | string (uuid) |  |  |
| `case_id` | query | string (uuid) |  |  |
| `kind` | query | `upload`, `link` |  |  |
| `q` | query | string |  | 1–200 characters |
| `sort` | query | `name`, `-name`, `size_bytes`, `-size_bytes`, `created_at`, `-created_at`, `updated_at`, `-updated_at` |  | Sort by name, size_bytes, created_at, updated_at; prefix "-" for descending. |
| `include_deleted` | query | `true`, `false` |  |  |

### Response 200

| Field | Type | Always present | Notes |
| --- | --- | --- | --- |
| `data` | array of [Document](/api/reference/objects.md#document) | yes |  |
| `next_cursor` | string or null | yes |  |

Errors are problem details with a stable `code`: see [Errors](/errors.md).

## Add a link to a file (SharePoint, OneDrive or other https)

`POST https://staging-api.naruskacrm.com/v1/documents`

JSON only: a link to a file kept elsewhere. Upload a file with POST /v1/documents/upload. Needs write access to every linked record.

### Request body

| Field | Type | Required | Notes |
| --- | --- | --- | --- |
| `name` | string | yes | 1–300 characters |
| `url` | string | yes | at most 2000 characters |
| `links` | object | yes |  |
| `links.contact_ids` | array of string (uuid) |  | at most 20 items |
| `links.account_ids` | array of string (uuid) |  | at most 20 items |
| `links.opportunity_ids` | array of string (uuid) |  | at most 20 items |
| `links.quote_ids` | array of string (uuid) |  | at most 20 items |
| `links.case_ids` | array of string (uuid) |  | at most 20 items |
| `source_system` | string or null |  | 1–100 characters |
| `source_id` | string or null |  | 1–500 characters |

### Response 201

Returns: [Document](/api/reference/objects.md#document).

Errors are problem details with a stable `code`: see [Errors](/errors.md).

## Get a document

`GET https://staging-api.naruskacrm.com/v1/documents/{id}`

### Parameters

| Parameter | In | Type | Required | Notes |
| --- | --- | --- | --- | --- |
| `id` | path | string (uuid) | yes |  |

### Response 200

Returns: [Document](/api/reference/objects.md#document).

Errors are problem details with a stable `code`: see [Errors](/errors.md).

## Rename a document

`PATCH https://staging-api.naruskacrm.com/v1/documents/{id}`

### Parameters

| Parameter | In | Type | Required | Notes |
| --- | --- | --- | --- | --- |
| `id` | path | string (uuid) | yes |  |

### Request body

| Field | Type | Required | Notes |
| --- | --- | --- | --- |
| `name` | string | yes | 1–300 characters |

### Response 200

Returns: [Document](/api/reference/objects.md#document).

Errors are problem details with a stable `code`: see [Errors](/errors.md).

## Delete a document (soft delete)

`DELETE https://staging-api.naruskacrm.com/v1/documents/{id}`

Anyone who can edit a linked record may delete it (Undo works for 7 days); admins can restore it for 30 days. The file is kept until the document is purged.

### Parameters

| Parameter | In | Type | Required | Notes |
| --- | --- | --- | --- | --- |
| `id` | path | string (uuid) | yes |  |

### Response 204

Done.
No body.

Errors are problem details with a stable `code`: see [Errors](/errors.md).

## Upload a file (paid plans)

`POST https://staging-api.naruskacrm.com/v1/documents/upload`

The raw file is the body, with its Content-Type and Content-Length (at most 25 MB); `name` and at least one linked record id are query parameters. Streamed to storage, never buffered. Refused on the free plan. An Idempotency-Key covers the method, path, query, length and type, not the bytes.

### Parameters

| Parameter | In | Type | Required | Notes |
| --- | --- | --- | --- | --- |
| `name` | query | string | yes | 1–300 characters |
| `contact_id` | query | string (uuid) |  |  |
| `account_id` | query | string (uuid) |  |  |
| `opportunity_id` | query | string (uuid) |  |  |
| `quote_id` | query | string (uuid) |  |  |
| `case_id` | query | string (uuid) |  |  |

### Request body

The body is `application/octet-stream` bytes.

### Response 201

Returns: [Document](/api/reference/objects.md#document).

Errors are problem details with a stable `code`: see [Errors](/errors.md).

## Attach a file from an https URL or base64 content (paid plans)

`POST https://staging-api.naruskacrm.com/v1/documents/import`

For agents (MCP attach_document, B11): the API fetches `url` (https on a public host only; redirects are not followed; at most 25 MB within 15 s) or decodes `content_base64` (at most 5 MB), and stores it as an upload. Counts as an upload: refused on the free plan.

### Request body

| Field | Type | Required | Notes |
| --- | --- | --- | --- |
| `name` | string | yes | 1–300 characters |
| `url` | string |  | at most 2000 characters |
| `content_base64` | string |  | at most 7000000 characters |
| `content_type` | string |  | at most 200 characters |
| `links` | object | yes |  |
| `links.contact_ids` | array of string (uuid) |  | at most 20 items |
| `links.account_ids` | array of string (uuid) |  | at most 20 items |
| `links.opportunity_ids` | array of string (uuid) |  | at most 20 items |
| `links.quote_ids` | array of string (uuid) |  | at most 20 items |
| `links.case_ids` | array of string (uuid) |  | at most 20 items |

### Response 201

Returns: [Document](/api/reference/objects.md#document).

Errors are problem details with a stable `code`: see [Errors](/errors.md).

## Restore a deleted document

`POST https://staging-api.naruskacrm.com/v1/documents/{id}/restore`

Admins only. Its links deleted with it come back too.

### Parameters

| Parameter | In | Type | Required | Notes |
| --- | --- | --- | --- | --- |
| `id` | path | string (uuid) | yes |  |

### Response 200

Returns: [Document](/api/reference/objects.md#document).

Errors are problem details with a stable `code`: see [Errors](/errors.md).

## Link a document to another record

`POST https://staging-api.naruskacrm.com/v1/documents/{id}/links/{type}/{recordId}`

`type` is contacts, accounts, opportunities, quotes or cases. Needs write access to the document and the record.

### Parameters

| Parameter | In | Type | Required | Notes |
| --- | --- | --- | --- | --- |
| `id` | path | string (uuid) | yes |  |
| `type` | path | `contacts`, `accounts`, `opportunities`, `quotes`, `cases` | yes |  |
| `recordId` | path | string (uuid) | yes |  |

### Response 201

Returns: [Document](/api/reference/objects.md#document).

Errors are problem details with a stable `code`: see [Errors](/errors.md).

## Unlink a document from a record

`DELETE https://staging-api.naruskacrm.com/v1/documents/{id}/links/{type}/{recordId}`

A document keeps at least one link: to remove the last one, delete the document instead (it can be undone).

### Parameters

| Parameter | In | Type | Required | Notes |
| --- | --- | --- | --- | --- |
| `id` | path | string (uuid) | yes |  |
| `type` | path | `contacts`, `accounts`, `opportunities`, `quotes`, `cases` | yes |  |
| `recordId` | path | string (uuid) | yes |  |

### Response 204

Done.
No body.

Errors are problem details with a stable `code`: see [Errors](/errors.md).

## Download a file

`GET https://staging-api.naruskacrm.com/v1/documents/{id}/content`

Always as an attachment, with X-Content-Type-Options: nosniff and Content-Security-Policy: sandbox; the type is the stored one for PDF, images, Office, text and zip, else application/octet-stream.

### Parameters

| Parameter | In | Type | Required | Notes |
| --- | --- | --- | --- | --- |
| `id` | path | string (uuid) | yes |  |

### Response 200

The file.
Returns `application/octet-stream` bytes.

Errors are problem details with a stable `code`: see [Errors](/errors.md).

## A 15-minute download link

`POST https://staging-api.naruskacrm.com/v1/documents/{id}/signed-link`

For agents that cannot send their token to another URL. Anyone holding the link can download the file for 15 minutes, as you: it stops working if you lose access, the document is deleted, or the token or session you made it with is revoked or ends.

### Parameters

| Parameter | In | Type | Required | Notes |
| --- | --- | --- | --- | --- |
| `id` | path | string (uuid) | yes |  |

### Response 200

Returns: [SignedLink](/api/reference/objects.md#signedlink).

Errors are problem details with a stable `code`: see [Errors](/errors.md).

## Download through a signed link

`GET https://staging-api.naruskacrm.com/v1/files/{token}`

No Authorization header: the token is the credential (B10). Valid 15 minutes.

No bearer token: see the description.

### Parameters

| Parameter | In | Type | Required | Notes |
| --- | --- | --- | --- | --- |
| `token` | path | string | yes | at most 500 characters |

### Response 200

The file.
Returns `application/octet-stream` bytes.

Errors are problem details with a stable `code`: see [Errors](/errors.md).

