# Add or update an attachment

`PUT https://api.cademi.com.br/api/v3/products/{product_id}/lessons/{lesson_id}/attachments/{file_id}`

Operation ID: `lessons.attachments.update` · API v3

Attaches a file to the lesson body, or updates the title and kind of an existing attachment for the same file. The operation is idempotent per file ID: it returns `201` when the attachment is added and `200` when an existing attachment is updated.

Send the lesson's current `ETag` in the `If-Match` header to avoid overwriting a newer version. Replicated lessons are read-only, and requests to change them return `replica_readonly`.

Required permissions: `lessons.update`.

## Parameters

| Name | In | Type | Required | Description |
|---|---|---|---|---|
| `product_id` | path | string | yes |  |
| `lesson_id` | path | string | yes |  |
| `file_id` | path | string | yes |  |
| `If-Match` | header | string | no |  |

## Request body

Content type: `application/json`.

| Field | Type | Required | Description |
|---|---|---|---|
| `kind` | string, one of `file`, `image` | no |  |
| `title` | string or null | no |  |

## Responses

### 200

The lesson already had an attachment for this file. Returns the updated attachment.

Body: `data`: LessonAttachment.

Fields of LessonAttachment:

| Field | Type | Required | Description |
|---|---|---|---|
| `file_id` | string or null | yes | Public ID of the attached file, or null for legacy attachments that are not linked to a file. |
| `kind` | string, one of `file`, `image` | yes |  |
| `object` | string, one of `lesson_attachment` | yes |  |
| `position` | integer | yes | Index of the attachment block within the lesson body. |
| `title` | string | yes |  |
| `url` | string | yes |  |

### 201

Returns the newly added attachment.

Body: `data`: LessonAttachment.

Fields of LessonAttachment:

| Field | Type | Required | Description |
|---|---|---|---|
| `file_id` | string or null | yes | Public ID of the attached file, or null for legacy attachments that are not linked to a file. |
| `kind` | string, one of `file`, `image` | yes |  |
| `object` | string, one of `lesson_attachment` | yes |  |
| `position` | integer | yes | Index of the attachment block within the lesson body. |
| `title` | string | yes |  |
| `url` | string | yes |  |

### 401

The credential is missing, malformed, expired, or revoked.

Body: Error.

### 403

The current credentials do not have the permission required by this operation.

Body: Error.

### 404

The lesson was not found in the product or is not accessible with the current credentials.

Body: Error.

### 412

The lesson has changed since the revision supplied in If-Match.

Body: Error.

### 422

The request body or query parameters failed validation.

Body: ValidationFailed.

Full schema: https://cademi.dev/openapi/v3.json
