## Attach a file to a checklist item by content

`POST /v1/tasks/:taskId/checklist/:itemId/attachments/content`

Uploads a file to the "Uploaded files" folder on the Drive of the user on whose behalf the call is made, and attaches it to a task checklist item.

## Parameters

| Parameter | Type | Required | Description |
|----------|-----|:-----:|----------|
| `taskId` (path) | number | yes | Task ID. List: [`GET /v1/tasks`](/docs/entities/tasks/list) |
| `itemId` (path) | number | yes | Checklist item ID. List of items: [`GET /v1/tasks/:taskId/checklist`](/docs/entities/tasks/checklist/list) |

## Request fields (body)

| Field | Type | Required | Description |
|------|-----|:-----:|----------|
| `attachmentParameters` | object | yes | The file to attach |
| `attachmentParameters.NAME` | string | yes | File name with an extension, for example `notes.txt`. The file is saved on Drive under this name |
| `attachmentParameters.CONTENT` | string | yes | File content in base64 |

## Examples

### curl — personal key

```bash
curl -X POST "https://vibecode.bitrix24.com/v1/tasks/4218/checklist/276/attachments/content" \
  -H "X-Api-Key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"attachmentParameters":{"NAME":"notes.txt","CONTENT":"QnVpbGQgY2hlY2sgbm90ZXM="}}'
```

### curl — OAuth application

```bash
curl -X POST "https://vibecode.bitrix24.com/v1/tasks/4218/checklist/276/attachments/content" \
  -H "X-Api-Key: YOUR_APP_KEY" \
  -H "Authorization: Bearer USER_SESSION_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"attachmentParameters":{"NAME":"notes.txt","CONTENT":"QnVpbGQgY2hlY2sgbm90ZXM="}}'
```

### JavaScript — personal key

```javascript
const content = Buffer.from('Build check notes').toString('base64')

const res = await fetch('https://vibecode.bitrix24.com/v1/tasks/4218/checklist/276/attachments/content', {
  method: 'POST',
  headers: {
    'X-Api-Key': 'YOUR_API_KEY',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    attachmentParameters: { NAME: 'notes.txt', CONTENT: content },
  }),
})

const { success, data } = await res.json()
console.log('Item:', data?.checkListItem?.id)
```

### JavaScript — OAuth application

```javascript
const content = Buffer.from('Build check notes').toString('base64')

const res = await fetch('https://vibecode.bitrix24.com/v1/tasks/4218/checklist/276/attachments/content', {
  method: 'POST',
  headers: {
    'X-Api-Key': 'YOUR_APP_KEY',
    'Authorization': 'Bearer USER_SESSION_TOKEN',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    attachmentParameters: { NAME: 'notes.txt', CONTENT: content },
  }),
})

const { success, data } = await res.json()
```

## Response fields

| Field | Type | Description |
|------|-----|----------|
| `success` | boolean | `true` if the request succeeded |
| `data.checkListItem` | object | The checklist item as it was before the file was added |
| `data.checkListItem.id` | number | Item ID |
| `data.checkListItem.copiedId` | number \| null | ID of the item this one was copied from. `null` — the item was not copied |
| `data.checkListItem.userId` | number | ID of the user on whose behalf the call is made |
| `data.checkListItem.createdBy` | number | ID of the item author. List: [`GET /v1/users`](/docs/entities/users/list) |
| `data.checkListItem.parentId` | number | Parent item ID. `0` — a top-level item |
| `data.checkListItem.title` | string | Item text |
| `data.checkListItem.sortIndex` | number | Position of the item among items with the same parent: the lower the number, the higher the item |
| `data.checkListItem.displaySortIndex` | string | Item number for display. An empty string in this method's response |
| `data.checkListItem.isComplete` | boolean | Whether the item is completed |
| `data.checkListItem.isImportant` | boolean | Whether the item is marked as important |
| `data.checkListItem.completedCount` | number | Number of completed sub-items. `0` in this method's response |
| `data.checkListItem.members` | array | Item members — objects with the fields `id`, `type`, `name`, `personalPhoto`, `personalGender`, `image`, `isCollaber`. `id` is the user ID as a string; `type`: `A` — participant, `U` — observer |
| `data.checkListItem.attachments` | array \| object | Item attachments before the call. An empty array — the item had no attachments. Otherwise an object where the key is the attachment ID and the value is the Drive file ID prefixed with the letter `n` |
| `data.checkListItem.nodeId` | null | Node key from [saving the checklist](/docs/entities/tasks/checklist-actions/tree). `null` in this method's response |
| `data.checkListItem.taskId` | number | Task ID |

## Response example

The file is attached to an item that had no attachments before the call:

```json
{
  "success": true,
  "data": {
    "checkListItem": {
      "id": 276,
      "copiedId": null,
      "userId": 1295,
      "createdBy": 1295,
      "parentId": 268,
      "title": "Check the build",
      "sortIndex": 1,
      "displaySortIndex": "",
      "isComplete": true,
      "isImportant": true,
      "completedCount": 0,
      "members": [
        {
          "id": "1295",
          "type": "U",
          "name": "John Smith",
          "personalPhoto": "33093",
          "personalGender": "",
          "image": "https://example.bitrix24.com/...",
          "isCollaber": false
        }
      ],
      "attachments": [],
      "nodeId": null,
      "taskId": 4218
    }
  }
}
```

## Error response example

422 — `attachmentParameters` has no `CONTENT`:

```json
{
  "success": false,
  "error": {
    "code": "BITRIX_ERROR",
    "message": "Error adding attachment",
    "b24Code": "0"
  }
}
```

## Errors

| HTTP | Code | Description |
|------|-----|----------|
| 400 | `INVALID_PARAMS` | `taskId` is not a positive integer. Message `taskId must be a positive integer` |
| 400 | `INVALID_PARAMS` | `itemId` is not a positive integer. Message `itemId must be a positive integer` |
| 400 | `INVALID_PARAMS` | The body is missing or is not a JSON object. Message `JSON object body is required` |
| 400 | `INVALID_PARAMS` | `attachmentParameters` is missing or is not an object, for example a string. Message `attachmentParameters must be an object` |
| 401 | `MISSING_API_KEY` | `X-Api-Key` is missing |
| 401 | `TOKEN_MISSING` | The key has no Bitrix24 tokens |
| 403 | `SCOPE_DENIED` | The key lacks the `task` scope |
| 403 | `WRITE_BLOCKED_READONLY_KEY` | The key is in read-only mode. `error.details.switchUrl` contains the URL of the section where the mode is changed |
| 413 | `PAYLOAD_TOO_LARGE` | The request body, including the base64 file content, exceeds 1 MiB |
| 415 | `FST_ERR_CTP_INVALID_MEDIA_TYPE` | A body with a `Content-Type` the API does not parse, for example `application/xml` |
| 404 | `TASK_NOT_FOUND` | The task is missing or inaccessible and the core returned the legacy named task-not-found signature |
| 404 | `NOT_FOUND` | The `itemId` item is missing, belongs to another task or is inaccessible. This also covers an unnamed task access denial in Russian, English, German or Kazakh; this denial does not distinguish a missing task from denied access |
| 422 | `BITRIX_ERROR` | Another Bitrix24 error, including an unrecognized core denial |
| 422 | `BITRIX_ERROR` | `attachmentParameters` has no `CONTENT` or `NAME`. The message is in the Bitrix24 account language, for example `Error adding attachment` |
| 429 | `RATE_LIMITED` | Request rate exceeded. The effective cap is in the `x-ratelimit-limit` header |

The full list of common API errors — [Errors](/docs/errors).

## Known specifics

**Read the item to get the new attachment ID.** The attachment created by the call is visible in [`GET /v1/tasks/:taskId/checklist/:itemId`](/docs/entities/tasks/checklist/get): its ID is a key of the `attachments` object, and `fileId` is the Drive file ID.

**Removing the attachment deletes the file from Drive.** Details — [Remove checklist item attachments](/docs/entities/tasks/checklist-actions/attachments-remove). To keep the file on Drive, upload it with [`POST /v1/files/upload`](/docs/entities/files/upload) and attach it [from Drive](/docs/entities/tasks/checklist-actions/attachments-disk).

**A string that is not base64 is accepted without an error.** If `CONTENT` is not base64-encoded, the method returns `200`, and a file with corrupted content appears on Drive. Encode the content before the call, as in the JavaScript examples.

**This method cannot attach a file larger than 768 KiB.** The request body is limited to 1 MiB, and base64 makes the file a third larger. Upload a larger file with [`POST /v1/files/upload`](/docs/entities/files/upload) and attach it [from Drive](/docs/entities/tasks/checklist-actions/attachments-disk).

## See also

- [Checklist actions and task file](/docs/entities/tasks/checklist-actions)
- [Attach Drive files to a checklist item](/docs/entities/tasks/checklist-actions/attachments-disk)
- [Remove checklist item attachments](/docs/entities/tasks/checklist-actions/attachments-remove)
- [Get a checklist item](/docs/entities/tasks/checklist/get)
- [Upload file](/docs/entities/files/upload)
- [Tasks](/docs/entities/tasks)
