## Create field

`POST /v1/userfields/tasks`

Creates a task user field. The field is shared across the whole Bitrix24 account: it appears right away in every task for all employees.

Pass the field properties flat at the JSON root — without a `fields` wrapper.

## Request fields (body)

| Field | Type | Required | Description |
|------|-----|:-----:|---------|
| `fieldName` | string | yes | System field name. Stored in upper case with the `UF_` prefix: `UF_REVIEW_STAGE` is saved as is, `request_channel` becomes `UF_REQUEST_CHANNEL` |
| `userTypeId` | string | yes | Field type from the [type catalog](/docs/userfields/tasks/types), for example `string`, `enumeration`, `double` |
| `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": "Request channel", "en": "Request channel" }`; in the remaining languages the field name becomes the label. The label does not go into `errorMessage` and `helpMessage`: those hold the field name |
| `multiple` | boolean | no | Multiple values in one task. Defaults to `false`. Can be set only at creation. A `boolean` field cannot be multiple |
| `mandatory` | boolean | no | Required field. Defaults to `false` |
| `sort` | integer | no | Field order — a non-negative integer. Defaults to `100` |
| `settings` | object | no | Field settings; the set of keys depends on `userTypeId`. Keys that are not passed get default values — the sets for `string` and `enumeration` are listed on the [Get field](/docs/userfields/tasks/get) page |
| `items` | array | no | Options of an `enumeration` field. Not accepted for other types |
| `items[].value` | string | yes | Option name — a non-empty string |
| `items[].sort` | integer | no | Option order — an integer greater than `0`. Without `sort` the option gets `500`, and the order of options in the response no longer matches the order you passed |
| `items[].def` | boolean | no | Default option. A field without `multiple` can have only one such option |
| `items[].xmlId` | string | no | External option ID. Generated automatically if not passed |

The method accepts no other properties: an unknown key, such as `xmlId` of the field itself, is rejected with `400 INVALID_PARAMS`.

## Examples

### curl — personal key

```bash
curl -X POST "https://vibecode.bitrix24.com/v1/userfields/tasks" \
  -H "X-Api-Key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "fieldName": "UF_REVIEW_STAGE",
    "userTypeId": "enumeration",
    "label": "Review stage",
    "mandatory": true,
    "sort": 500,
    "items": [
      { "value": "New", "xmlId": "new", "sort": 10, "def": true },
      { "value": "Under review", "xmlId": "review", "sort": 20 },
      { "value": "Accepted", "xmlId": "accepted", "sort": 30 }
    ]
  }'
```

### curl — OAuth application

```bash
curl -X POST "https://vibecode.bitrix24.com/v1/userfields/tasks" \
  -H "X-Api-Key: YOUR_APP_KEY" \
  -H "Authorization: Bearer USER_SESSION_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "fieldName": "UF_REVIEW_STAGE",
    "userTypeId": "enumeration",
    "label": "Review stage",
    "mandatory": true,
    "sort": 500,
    "items": [
      { "value": "New", "xmlId": "new", "sort": 10, "def": true },
      { "value": "Under review", "xmlId": "review", "sort": 20 },
      { "value": "Accepted", "xmlId": "accepted", "sort": 30 }
    ]
  }'
```

### JavaScript — personal key

```javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/userfields/tasks', {
  method: 'POST',
  headers: {
    'X-Api-Key': 'YOUR_API_KEY',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    fieldName: 'UF_REVIEW_STAGE',
    userTypeId: 'enumeration',
    label: 'Review stage',
    mandatory: true,
    sort: 500,
    items: [
      { value: 'New', xmlId: 'new', sort: 10, def: true },
      { value: 'Under review', xmlId: 'review', sort: 20 },
      { value: 'Accepted', xmlId: 'accepted', sort: 30 },
    ],
  }),
})

const { success, data } = await res.json()
console.log('Created field with id:', data.id)
```

### JavaScript — OAuth application

```javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/userfields/tasks', {
  method: 'POST',
  headers: {
    'X-Api-Key': 'YOUR_APP_KEY',
    'Authorization': 'Bearer USER_SESSION_TOKEN',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    fieldName: 'UF_REVIEW_STAGE',
    userTypeId: 'enumeration',
    label: 'Review stage',
    mandatory: true,
    sort: 500,
    items: [
      { value: 'New', xmlId: 'new', sort: 10, def: true },
      { value: 'Under review', xmlId: 'review', sort: 20 },
      { value: 'Accepted', xmlId: 'accepted', sort: 30 },
    ],
  }),
})

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

## Response fields

| Field | Type | Description |
|------|-----|---------|
| `success` | boolean | Always `true` on success |
| `data` | object | The whole created field — in the same shape as in the [Get field](/docs/userfields/tasks/get) response |
| `data.id` | number | Numeric ID of the created field |
| `data.fieldName` | string | Final field name in the `UF_*` format |

The response comes with HTTP status `201 Created`.

## Response example

The labels in the example are trimmed to two languages — `en` and `ru`. The response has more keys: one per language.

```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": "Review stage",
      "ru": "Review stage"
    },
    "listColumnLabel": {
      "en": "Review stage",
      "ru": "Review stage"
    },
    "listFilterLabel": {
      "en": "Review stage",
      "ru": "Review 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": "Under review",
        "sort": "20",
        "def": "N",
        "xmlId": "review"
      },
      {
        "id": 4049,
        "value": "Accepted",
        "sort": "30",
        "def": "N",
        "xmlId": "accepted"
      }
    ]
  }
}
```

## Error response example

400 — the required `fieldName` was not passed:

```json
{
  "success": false,
  "error": {
    "code": "MISSING_REQUIRED_FIELDS",
    "message": "fieldName and userTypeId are required"
  }
}
```

## Errors

| HTTP | Code | Description |
|------|-----|---------|
| 400 | `MISSING_REQUIRED_FIELDS` | `fieldName` or `userTypeId` was not passed |
| 400 | `INVALID_PARAMS` | The request body is not an object, an unknown key was passed, or a value has the wrong type — for example, `sort` as a string |
| 400 | `INVALID_PARAMS` | A `boolean` field with `multiple: true` |
| 400 | `INVALID_PARAMS` | `items` for a field whose type is not `enumeration` |
| 400 | `INVALID_PARAMS` | An option without `value` or with `sort` less than `1` |
| 400 | `INVALID_PARAMS` | More than one option with `def: true` for a field without `multiple` |
| 422 | `BITRIX_ERROR` | Unknown `userTypeId` — the message is `The custom type is invalid.` |
| 422 | `BITRIX_ERROR` | A field with this name already exists — the message is `The field UF_REVIEW_STAGE for entity TASKS_TASK already exists.` |
| 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 field was created is unknown. The request was not retried automatically: find the field in the [list](/docs/userfields/tasks/list) by `fieldName` before creating it again |
| 502 | `TASK_USERFIELD_READBACK_FAILED` | The field was created, but reading it back after the write failed. The response contains `error.fieldId` — the field ID — and `error.writeConfirmed: true`. Retry the read by `fieldId`, not the creation |
| 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

**The API creates a task even without a value for a required field.** [`POST /v1/tasks`](/docs/entities/tasks/create) creates a task without the field value even when the field has `mandatory: true`. In that task the field value is `null`, even if a list option has `def: true`.

**A new field is visible in tasks immediately.** After creation the field arrives in [`GET /v1/tasks/:id`](/docs/entities/tasks/get) under its camelCase name — `ufReviewStage` for `UF_REVIEW_STAGE`.

## See also

- [Get field](/docs/userfields/tasks/get)
- [Update field](/docs/userfields/tasks/update)
- [Delete field](/docs/userfields/tasks/delete)
- [Field types](/docs/userfields/tasks/types)
- [Task fields](/docs/userfields/tasks)
- [Tasks](/docs/entities/tasks)
- [User fields](/docs/userfields)
