# Documents API

> List, upload and download stored documents. GET /api/v1/documents, POST /api/v1/documents, GET /api/v1/documents/{id}, GET /api/v1/documents/{id}/file.

4 operations. Each needs an API key with the permission shown; see [API keys and permissions](https://staffedly.com/docs/developers/api-keys).

| Operation | Permission |
| --- | --- |
| [`GET /api/v1/documents`](#get-api-v1-documents) | `documents:read` |
| [`POST /api/v1/documents`](#post-api-v1-documents) | `documents:write` |
| [`GET /api/v1/documents/{id}`](#get-api-v1-documents-id) | `documents:read` |
| [`GET /api/v1/documents/{id}/file`](#get-api-v1-documents-id-file) | `documents:read` |

## GET /api/v1/documents

Stored documents: uploads and signed records. Deleted files are left out; archived ones only when asked for.

- **Permission:** `documents:read`
- **Returns:** a page of records: `{ data, hasMore, nextCursor }`, status 200

**Query parameters** (all optional)

| Name | Description |
| --- | --- |
| `providerId` | Only this person. |
| `facilityId` | Only this site. |
| `category` | tax_form, contract, policy, id or other. |
| `source` | upload or signed. |
| `includeArchived` | true to include archived documents. |
| `limit` | Rows per page, 1 to 200. Default 50. |
| `cursor` | The nextCursor value from the previous page. |

**Fields in each record:** `id`, `providerId`, `facilityId`, `title`, `category`, `source`, `fileName`, `mimeType`, `sizeBytes`, `sha256`, `expiresAt`, `signRequestId`, `requirementId`, `archived`, `createdAt`

```bash
curl "https://app.staffedly.com/api/v1/documents?limit=50" \
  -H "Authorization: Bearer $STAFFEDLY_API_KEY"
```

## POST /api/v1/documents

Upload a file to a person's or a site's record. Send multipart/form-data, not JSON: a `file` part (PDF, JPG or PNG, up to 10 MB) plus the fields below. Idempotency-Key is not honoured on this one.

- **Permission:** `documents:write`
- **Returns:** one record: `{ data }`, status 201

**Form fields** (multipart/form-data)

| Field | Description |
| --- | --- |
| `file` | Required. The file itself. |
| `providerId` | The person it belongs to. This or facilityId is required. |
| `facilityId` | The site it belongs to. |
| `title` | Shown in lists. Default: the file's name. |
| `category` | tax_form, contract, policy, id or other. Default other. |
| `expiresAt` | YYYY-MM-DD, if it expires. |
| `requirementId` | The required document this file satisfies, if any. |

**Fields in each record:** `id`, `providerId`, `facilityId`, `title`, `category`, `source`, `fileName`, `mimeType`, `sizeBytes`, `sha256`, `expiresAt`, `signRequestId`, `requirementId`, `archived`, `createdAt`

```bash
curl -X POST "https://app.staffedly.com/api/v1/documents" \
  -H "Authorization: Bearer $STAFFEDLY_API_KEY" \
  -F "file=@agreement.pdf" \
  -F "providerId=<providerId>" \
  -F "category=contract"
```

## GET /api/v1/documents/{id}

One stored document.

- **Permission:** `documents:read`
- **Returns:** one record: `{ data }`, status 200

**Path**

| Name | Description |
| --- | --- |
| `id` | The record's id. |

**Fields in each record:** `id`, `providerId`, `facilityId`, `title`, `category`, `source`, `fileName`, `mimeType`, `sizeBytes`, `sha256`, `expiresAt`, `signRequestId`, `requirementId`, `archived`, `createdAt`

```bash
curl "https://app.staffedly.com/api/v1/documents/<id>" \
  -H "Authorization: Bearer $STAFFEDLY_API_KEY"
```

## GET /api/v1/documents/{id}/file

The file itself (PDF, JPG or PNG bytes, not JSON). Each download is recorded in the audit trail.

- **Permission:** `documents:read`
- **Returns:** one record: `{ data }`, status 200

**Path**

| Name | Description |
| --- | --- |
| `id` | The record's id. |

```bash
curl "https://app.staffedly.com/api/v1/documents/<id>/file" \
  -H "Authorization: Bearer $STAFFEDLY_API_KEY"
```

