## Update field

`PATCH /v1/userfields/tasks/:id`

Changes the label, required flag, sort order, settings, and list options of a task user field. The name, type, and multiplicity of a field cannot be changed after creation.

## Parameters

| Parameter | Type | Required | Description |
|----------|-----|:-----:|---------|
| `:id` (path) | number | yes | Numeric identifier of the field from the response of [`GET /v1/userfields/tasks`](/docs/userfields/tasks/list) or [`POST /v1/userfields/tasks`](/docs/userfields/tasks/create) |

## Request fields (body)

Pass at least one property. Properties are passed flat at the JSON root — without a `fields` wrapper.

| Field | Type | Required | Description |
|------|-----|:-----:|---------|
| `label` | string \| object | no | Field label. A string is written to `editFormLabel`, `listColumnLabel`, and `listFilterLabel` in all languages. An object sets labels per language — `{ "ru": "Approval stage", "en": "Approval stage" }`; labels in the other languages become empty |
| `mandatory` | boolean | no | Required field |
| `sort` | integer | no | Field order — a non-negative integer |
| `settings` | object | no | Field settings; the set of keys depends on the type — [Get field](/docs/userfields/tasks/get) |
| `items` | array | no | Changes to the options of an `enumeration` field |
| `items[].id` | number | no | Identifier of an existing option from [`GET /v1/userfields/tasks/:id`](/docs/userfields/tasks/get). An element without `id` adds a new option |
| `items[].value` | string | yes | Option name — a non-empty string. Can be omitted only in an element with `del: true` |
| `items[].del` | boolean | no | `true` — delete the option with the specified `id` |
| `items[].sort` | integer | no | Option order — an integer greater than `0` |
| `items[].def` | boolean | no | Default option. To clear it on a field without `multiple`, mark another option with `def: true` in the same request |
| `items[].xmlId` | string | no | External identifier of the option. If omitted, an existing option keeps its current value |

## Examples

### curl — personal key

```bash
curl -X PATCH "https://vibecode.bitrix24.com/v1/userfields/tasks/6007967" \
  -H "X-Api-Key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "label": { "ru": "Approval stage", "en": "Approval stage" },
    "items": [
      { "id": 4047, "value": "Pending approval" },
      { "id": 4049, "del": true },
      { "value": "Approved", "xmlId": "approved", "sort": 40 }
    ]
  }'
```

### curl — OAuth application

```bash
curl -X PATCH "https://vibecode.bitrix24.com/v1/userfields/tasks/6007967" \
  -H "X-Api-Key: YOUR_APP_KEY" \
  -H "Authorization: Bearer USER_SESSION_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "label": { "ru": "Approval stage", "en": "Approval stage" },
    "items": [
      { "id": 4047, "value": "Pending approval" },
      { "id": 4049, "del": true },
      { "value": "Approved", "xmlId": "approved", "sort": 40 }
    ]
  }'
```

### JavaScript — personal key

```javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/userfields/tasks/6007967', {
  method: 'PATCH',
  headers: {
    'X-Api-Key': 'YOUR_API_KEY',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    label: { ru: 'Approval stage', en: 'Approval stage' },
    items: [
      { id: 4047, value: 'Pending approval' },
      { id: 4049, del: true },
      { value: 'Approved', xmlId: 'approved', sort: 40 },
    ],
  }),
})

const { success, data } = await res.json()
console.log(data.items.map((item) => item.value))
```

### JavaScript — OAuth application

```javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/userfields/tasks/6007967', {
  method: 'PATCH',
  headers: {
    'X-Api-Key': 'YOUR_APP_KEY',
    'Authorization': 'Bearer USER_SESSION_TOKEN',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    label: { ru: 'Approval stage', en: 'Approval stage' },
    items: [
      { id: 4047, value: 'Pending approval' },
      { id: 4049, del: true },
      { value: 'Approved', xmlId: 'approved', sort: 40 },
    ],
  }),
})

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

## Response fields

| Field | Type | Description |
|------|-----|---------|
| `success` | boolean | Always `true` on success |
| `data` | object | The whole field after the change — in the same shape as in the [Get field](/docs/userfields/tasks/get) response |
| `data.items` | array | All options of the field after the change, including those not mentioned in the request |

## Response example

Labels in the example are shortened to two languages — `en` and `ru`. In the other languages, the `editFormLabel`, `listColumnLabel`, and `listFilterLabel` labels in this response are empty: the `label` object in the request set only two languages.

```json
{
  "success": true,
  "data": {
    "id": 6007967,
    "entityId": "TASKS_TASK",
    "fieldName": "UF_REVIEW_STAGE",
    "userTypeId": "enumeration",
    "xmlId": null,
    "sort": "500",
    "multiple": "N",
    "mandatory": "Y",
    "showFilter": "N",
    "showInList": "Y",
    "editInList": "Y",
    "isSearchable": "N",
    "settings": {
      "DISPLAY": "LIST",
      "LIST_HEIGHT": 1,
      "CAPTION_NO_VALUE": "",
      "SHOW_NO_VALUE": "Y"
    },
    "editFormLabel": {
      "en": "Approval stage",
      "ru": "Approval stage"
    },
    "listColumnLabel": {
      "en": "Approval stage",
      "ru": "Approval stage"
    },
    "listFilterLabel": {
      "en": "Approval stage",
      "ru": "Approval stage"
    },
    "errorMessage": {
      "en": "UF_REVIEW_STAGE",
      "ru": "UF_REVIEW_STAGE"
    },
    "helpMessage": {
      "en": "UF_REVIEW_STAGE",
      "ru": "UF_REVIEW_STAGE"
    },
    "system": false,
    "items": [
      {
        "id": 4045,
        "value": "New",
        "sort": "10",
        "def": "Y",
        "xmlId": "new"
      },
      {
        "id": 4047,
        "value": "Pending approval",
        "sort": "20",
        "def": "N",
        "xmlId": "review"
      },
      {
        "id": 4051,
        "value": "Approved",
        "sort": "40",
        "def": "N",
        "xmlId": "approved"
      }
    ]
  }
}
```

## Error response example

400 — the body contains the immutable property `fieldName`:

```json
{
  "success": false,
  "error": {
    "code": "IMMUTABLE_FIELD",
    "message": "fieldName, userTypeId and multiple cannot be changed"
  }
}
```

## Errors

| HTTP | Code | Description |
|------|-----|---------|
| 400 | `INVALID_ID` | `:id` is not a positive integer — the request is rejected before it reaches Bitrix24 |
| 400 | `IMMUTABLE_FIELD` | The body contains `fieldName`, `userTypeId`, or `multiple` |
| 400 | `INVALID_PARAMS` | Empty body, an unknown key, or a value of the wrong type |
| 400 | `INVALID_PARAMS` | An `items` element without `value` and without `del: true`, or an option `sort` less than `1` |
| 400 | `INVALID_PARAMS` | The option `id` belongs to another field |
| 400 | `INVALID_PARAMS` | On a field without `multiple`, `def` is cleared from the default option and no other option is marked, or more than one option is marked |
| 400 | `INVALID_PARAMS` | `items` is passed for a field whose type is not `enumeration` |
| 404 | `ENTITY_NOT_FOUND` | There is no field with this `id`, or it belongs to another entity |
| 403 | `SYSTEM_FIELD_PROTECTED` | System field `UF_CRM_TASK`, `UF_TASK_WEBDAV_FILES`, or `UF_MAIL_MESSAGE` |
| 403 | `BITRIX_ACCESS_DENIED` | The key owner is not a Bitrix24 account administrator |
| 403 | `WRITE_BLOCKED_READONLY_KEY` | The key is in read-only mode |
| 403 | `TASK_CUSTOM_FIELDS_UNAVAILABLE` | The portal plan does not include task user fields |
| 403 | `SCOPE_DENIED` | The API key does not have the `task` scope |
| 502 | `TASK_USERFIELD_OUTCOME_UNKNOWN` | The connection to Bitrix24 dropped, or Bitrix24 returned a server error during the write — whether the change was applied is unknown. The request was not retried automatically: read the field before changing it again |
| 502 | `TASK_USERFIELD_READBACK_FAILED` | The change was written, but the field could not be read after the write. The response contains `error.fieldId` — the field ID — and `error.writeConfirmed: true`. Retry the read, not the update |
| 401 | `TOKEN_MISSING` | The key has no Bitrix24 tokens. For an application key, the `Authorization: Bearer USER_SESSION_TOKEN` header was not passed |
| 401 | `MISSING_API_KEY` | The `X-Api-Key` header is missing |

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

## Known specifics

**`items` describes only the changes.** An option that is not in the array stays unchanged. In the example, the "New" option was kept, "Accepted" was deleted, "In review" was renamed and kept its `xmlId`, and "Approved" was added.

## See also

- [Get field](/docs/userfields/tasks/get)
- [Create field](/docs/userfields/tasks/create)
- [Delete field](/docs/userfields/tasks/delete)
- [Task fields](/docs/userfields/tasks)
- [User fields](/docs/userfields)
