[{"data":1,"prerenderedAt":7},["ShallowReactive",2],{"docs-entities\u002Ftasks\u002Ffiles-attach":3,"docs-tabs-entities\u002Ftasks\u002Ffiles-attach":6},{"content":4,"lastmod":5},"## Attach a file to a task\n\n`POST \u002Fv1\u002Ftasks\u002F:taskId\u002Ffiles\u002Fattach`\n\nAttaches a file that is already on Bitrix24 Drive to a task: the task gets an attachment, and the file itself is not copied.\n\n## Parameters\n\n| Parameter | Type | Required | Description |\n|----------|-----|:-----:|----------|\n| `taskId` (path) | number | yes | Task ID. List: [`GET \u002Fv1\u002Ftasks`](\u002Fdocs\u002Fentities\u002Ftasks\u002Flist) |\n\n## Request fields (body)\n\n| Field | Type | Required | Description |\n|------|-----|:-----:|----------|\n| `fileId` | number | yes | Drive file ID — a positive integer, not prefixed with the letter `n`. List: [`GET \u002Fv1\u002Ffiles`](\u002Fdocs\u002Fentities\u002Ffiles\u002Flist). To upload a new file, use [`POST \u002Fv1\u002Ffiles\u002Fupload`](\u002Fdocs\u002Fentities\u002Ffiles\u002Fupload) |\n\n## Examples\n\n### curl — personal key\n\n```bash\ncurl -X POST \"https:\u002F\u002Fvibecode.bitrix24.com\u002Fv1\u002Ftasks\u002F4233\u002Ffiles\u002Fattach\" \\\n  -H \"X-Api-Key: YOUR_API_KEY\" \\\n  -H \"Content-Type: application\u002Fjson\" \\\n  -d '{\"fileId\":10867}'\n```\n\n### curl — OAuth application\n\n```bash\ncurl -X POST \"https:\u002F\u002Fvibecode.bitrix24.com\u002Fv1\u002Ftasks\u002F4233\u002Ffiles\u002Fattach\" \\\n  -H \"X-Api-Key: YOUR_APP_KEY\" \\\n  -H \"Authorization: Bearer USER_SESSION_TOKEN\" \\\n  -H \"Content-Type: application\u002Fjson\" \\\n  -d '{\"fileId\":10867}'\n```\n\n### JavaScript — personal key\n\n```javascript\nconst res = await fetch('https:\u002F\u002Fvibecode.bitrix24.com\u002Fv1\u002Ftasks\u002F4233\u002Ffiles\u002Fattach', {\n  method: 'POST',\n  headers: {\n    'X-Api-Key': 'YOUR_API_KEY',\n    'Content-Type': 'application\u002Fjson',\n  },\n  body: JSON.stringify({ fileId: 10867 }),\n})\n\nconst { success, data } = await res.json()\nconsole.log('Attachment ID:', data?.attachmentId)\n```\n\n### JavaScript — OAuth application\n\n```javascript\nconst res = await fetch('https:\u002F\u002Fvibecode.bitrix24.com\u002Fv1\u002Ftasks\u002F4233\u002Ffiles\u002Fattach', {\n  method: 'POST',\n  headers: {\n    'X-Api-Key': 'YOUR_APP_KEY',\n    'Authorization': 'Bearer USER_SESSION_TOKEN',\n    'Content-Type': 'application\u002Fjson',\n  },\n  body: JSON.stringify({ fileId: 10867 }),\n})\n\nconst { success, data } = await res.json()\n```\n\n## Response fields\n\n| Field | Type | Description |\n|------|-----|----------|\n| `success` | boolean | `true` if the request succeeded |\n| `data.attachmentId` | number | Attachment ID — the ID of the link between the file and the task, not the Drive file ID. The same number appears in the task's `ufTaskWebdavFiles` list: [`GET \u002Fv1\u002Ftasks\u002F:id`](\u002Fdocs\u002Fentities\u002Ftasks\u002Fget) |\n\n## Response example\n\nDrive file `10867` is attached to task `4233`, and the attachment has ID `597`:\n\n```json\n{\n  \"success\": true,\n  \"data\": {\n    \"attachmentId\": 597\n  }\n}\n```\n\n## Error response example\n\n422 — Drive has no file with this ID:\n\n```json\n{\n  \"success\": false,\n  \"error\": {\n    \"code\": \"BITRIX_ERROR\",\n    \"message\": \"File could not be found.\",\n    \"b24Code\": \"ERROR_CORE\"\n  }\n}\n```\n\n## Errors\n\n| HTTP | Code | Description |\n|------|-----|----------|\n| 400 | `INVALID_PARAMS` | The request failed validation for one of these reasons, and the message names it. `taskId` is not a positive integer: message `taskId must be a positive integer`. The body is not a JSON object, for example an array: message `JSON object body is required`. `fileId` is missing or is not a positive integer, including the string `\"10867\"` or `\"n10867\"`: message `fileId must be a positive integer` |\n| 400 | `FST_ERR_CTP_EMPTY_JSON_BODY` | An empty body with the `Content-Type: application\u002Fjson` header |\n| 401 | `MISSING_API_KEY` | `X-Api-Key` is missing |\n| 401 | `TOKEN_MISSING` | The key has no Bitrix24 tokens |\n| 403 | `SCOPE_DENIED` | The key lacks the `task` scope |\n| 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 |\n| 415 | `FST_ERR_CTP_INVALID_MEDIA_TYPE` | A body with a `Content-Type` the API does not parse, for example `application\u002Fxml` |\n| 422 | `BITRIX_ERROR` | Bitrix24 refused the call; `error.b24Code` tells the reasons apart. `ERROR_CORE`: Drive has no file with this `fileId`; the message is in the Bitrix24 account language, and on a `.com` account it is `File could not be found.` The same `ERROR_CORE` arrives when the employee on whose behalf the call is made has no access to the file; the message is in the Bitrix24 account language. `0`: the employee has no access to the task; the message is `Access denied`. This employee gets the same response for the `taskId` of a nonexistent task. The API specification declares `404 TASK_NOT_FOUND` for this case, but the Bitrix24 accounts we tested return this response instead |\n| 429 | `RATE_LIMITED` | Request rate exceeded. The effective cap is in the `x-ratelimit-limit` header |\n\nThe full list of common API errors — [Errors](\u002Fdocs\u002Ferrors).\n\n## Known specifics\n\n**Attaching the same file again adds a duplicate.** Each call with the same `fileId` adds one more attachment of that file to the task, and the response returns the ID of the first attachment. All task attachments are listed in the `ufTaskWebdavFiles` field of the [`GET \u002Fv1\u002Ftasks\u002F:id`](\u002Fdocs\u002Fentities\u002Ftasks\u002Fget) response. To keep a single copy, [update the task](\u002Fdocs\u002Fentities\u002Ftasks\u002Fupdate): setting the `ufTaskWebdavFiles` field to `[\"n10867\"]` replaces the entire attachment list with one attachment.\n\n**A nonexistent `taskId` does not always return an error.** The response depends on the employee on whose behalf the call is made: one gets `422 BITRIX_ERROR`, another gets `200` with `attachmentId`. In the second case the attachment is created but is not visible in any task. Before the call, check the task with [`GET \u002Fv1\u002Ftasks\u002F:id`](\u002Fdocs\u002Fentities\u002Ftasks\u002Fget).\n\n## See also\n\n- [Checklist actions and task file](\u002Fdocs\u002Fentities\u002Ftasks\u002Fchecklist-actions)\n- [Get task](\u002Fdocs\u002Fentities\u002Ftasks\u002Fget)\n- [Update task](\u002Fdocs\u002Fentities\u002Ftasks\u002Fupdate)\n- [Attach Drive files to a checklist item](\u002Fdocs\u002Fentities\u002Ftasks\u002Fchecklist-actions\u002Fattachments-disk)\n- [Files](\u002Fdocs\u002Fentities\u002Ffiles)\n- [Tasks](\u002Fdocs\u002Fentities\u002Ftasks)\n","2026-10-23",{},1795376996233]