# Add an attachment

`POST /v1/attachments`

Records an attachment whose bytes are already stored under their SHA-256 (the Blob port locally, an upload URL when hosted). Several attachments may share the same bytes.

Scope: `docs:write`. Undoable.

## Request

```bash
curl -X POST "https://api.lydie.co/v1/attachments" \
  -H "Authorization: Bearer $LYDIE_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "workspaceId": "01JCQ3TZ0WJ8K4M2X7T9R6N1PA",
    "filename": "string",
    "contentType": "string",
    "size": 0,
    "sha256": "string"
  }'
```

## Body

- `workspaceId` (string, required): (1–64 chars)
- `id` (ULID, optional): Client-minted id. Generated when omitted.
- `documentId` (ULID, optional, nullable): Default: `null`.
- `filename` (string, required): (1–255 chars)
- `contentType` (string, required): (1–255 chars)
- `size` (integer, required)
- `sha256` (string, required)

## Response

- `id` (ULID, required)
- `workspaceId` (string, required): (1–64 chars)
- `documentId` (ULID, required, nullable): The document it belongs to; null for workspace files.
- `filename` (string, required): (1–255 chars)
- `contentType` (string, required): (1–255 chars)
- `size` (integer, required)
- `sha256` (string, required)
- `createdAt` (timestamp, required)
- `updatedAt` (timestamp, required)
- `deletedAt` (timestamp, required, nullable)
- `createdBy` (string, optional, nullable): (≥ 1 chars)
- `updatedBy` (string, optional, nullable): (≥ 1 chars)

```json
{
  "id": "01JCQ3V5MZ8G4ZK2X7T9R6N1PB",
  "workspaceId": "01JCQ3TZ0WJ8K4M2X7T9R6N1PA",
  "documentId": null,
  "filename": "string",
  "contentType": "string",
  "size": 0,
  "sha256": "string",
  "createdAt": "2026-11-12T09:30:00.000Z",
  "updatedAt": "2026-11-12T09:30:00.000Z",
  "deletedAt": null,
  "createdBy": null,
  "updatedBy": null
}
```

Errors use the envelope described at https://developers.lydie.co/errors.md.
