For AI agents: markdown of this page — /docs-content-en/entities/tasks/files-attach.md documentation index — /llms.txt

Attach a file to a task

POST /v1/tasks/:taskId/files/attach

Attaches a file that is already on Bitrix24 Drive to a task: the task gets an attachment, and the file itself is not copied.

Parameters

Parameter Type Required Description
ParametertaskId (path) Typenumber Requiredyes DescriptionTask ID. List: GET /v1/tasks

Request fields (body)

Field Type Required Description
FieldfileId Typenumber Requiredyes DescriptionDrive file ID — a positive integer, not prefixed with the letter n. List: GET /v1/files. To upload a new file, use POST /v1/files/upload

Examples

curl — personal key

Terminal
curl -X POST "https://vibecode.bitrix24.com/v1/tasks/4233/files/attach" \
  -H "X-Api-Key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"fileId":10867}'

curl — OAuth application

Terminal
curl -X POST "https://vibecode.bitrix24.com/v1/tasks/4233/files/attach" \
  -H "X-Api-Key: YOUR_APP_KEY" \
  -H "Authorization: Bearer USER_SESSION_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"fileId":10867}'

JavaScript — personal key

javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/tasks/4233/files/attach', {
  method: 'POST',
  headers: {
    'X-Api-Key': 'YOUR_API_KEY',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({ fileId: 10867 }),
})

const { success, data } = await res.json()
console.log('Attachment ID:', data?.attachmentId)

JavaScript — OAuth application

javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/tasks/4233/files/attach', {
  method: 'POST',
  headers: {
    'X-Api-Key': 'YOUR_APP_KEY',
    'Authorization': 'Bearer USER_SESSION_TOKEN',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({ fileId: 10867 }),
})

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

Response fields

Field Type Description
Fieldsuccess Typeboolean Descriptiontrue if the request succeeded
Fielddata.attachmentId Typenumber DescriptionAttachment 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 /v1/tasks/:id

Response example

Drive file 10867 is attached to task 4233, and the attachment has ID 597:

JSON
{
  "success": true,
  "data": {
    "attachmentId": 597
  }
}

Error response example

422 — Drive has no file with this ID:

JSON
{
  "success": false,
  "error": {
    "code": "BITRIX_ERROR",
    "message": "File could not be found.",
    "b24Code": "ERROR_CORE"
  }
}

Errors

HTTP Code Description
HTTP400 CodeINVALID_PARAMS DescriptionThe 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
HTTP400 CodeFST_ERR_CTP_EMPTY_JSON_BODY DescriptionAn empty body with the Content-Type: application/json header
HTTP401 CodeMISSING_API_KEY DescriptionX-Api-Key is missing
HTTP401 CodeTOKEN_MISSING DescriptionThe key has no Bitrix24 tokens
HTTP403 CodeSCOPE_DENIED DescriptionThe key lacks the task scope
HTTP403 CodeWRITE_BLOCKED_READONLY_KEY DescriptionThe key is in read-only mode. error.details.switchUrl contains the URL of the section where the mode is changed
HTTP415 CodeFST_ERR_CTP_INVALID_MEDIA_TYPE DescriptionA body with a Content-Type the API does not parse, for example application/xml
HTTP422 CodeBITRIX_ERROR DescriptionBitrix24 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
HTTP429 CodeRATE_LIMITED DescriptionRequest rate exceeded. The effective cap is in the x-ratelimit-limit header

The full list of common API errors — Errors.

Known specifics

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 /v1/tasks/:id response. To keep a single copy, update the task: setting the ufTaskWebdavFiles field to ["n10867"] replaces the entire attachment list with one attachment.

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 /v1/tasks/:id.

See also