Create a Custom Field for Leads crm.lead.userfield.add

Scope: crm

Who can execute the method: CRM administrator

The method crm.lead.userfield.add creates a new custom field for leads.

Method Parameters

Required parameters are marked with *

Name
type

Description

fields*
object

Object format:

{
            field_1: value_1,
            field_2: value_2,
            ...,
            field_n: value_n,
        }
        
  • field_n — field name
  • value_n — field value

The list of available fields is described below.

An incorrect field in fields will be ignored

Parameter fields

Required parameters are marked with *

Name
type

Description

USER_TYPE_ID*
string

Data type of the custom field. Possible values:

  • string — string
  • integer — integer
  • double — number
  • boolean — yes/no
  • datetime — date/time
  • date — date
  • money — money
  • url — link
  • address — address
  • enumeration — list
  • file — file
  • employee — employee binding
  • crm_status — binding to CRM directory
  • iblock_section — binding to information block sections
  • iblock_element — binding to information block elements
  • crm — binding to CRM entities
  • custom field types

FIELD_NAME*
string

Field code. Unique.

The system limit for the field code is 20 characters. The custom field name is always prefixed with UF_CRM_, meaning the actual name length is 13 characters.

Allowed characters: A-Z, 0-9, and _

LABEL
string

Default name of the custom field.

The provided value will be set in the following fields: LIST_FILTER_LABEL, LIST_COLUMN_LABEL, EDIT_FORM_LABEL, ERROR_MESSAGE, HELP_MESSAGE, if no value is provided for them

XML_ID
string

External code

LIST_FILTER_LABEL
string|lang_map

Filter label in the list.

When a string is provided, it will be set for all language identifiers.

When a lang_map type value is provided, the value from LABEL will be set for all languages not provided.

By default, the value passed in LABEL is set for all language identifiers

LIST_COLUMN_LABEL
string|lang_map

Header in the list.

When a string is provided, it will be set for all language identifiers.

When a lang_map type value is provided, the value from LABEL will be set for all languages not provided.

By default, the value passed in LABEL is set for all language identifiers

EDIT_FORM_LABEL
string|lang_map

Label in the edit form.

When a string is provided, it will be set for all language identifiers.

When a lang_map type value is provided, the value from LABEL will be set for all languages not provided.

By default, the value passed in LABEL is set for all language identifiers

ERROR_MESSAGE
string|lang_map

Error message

HELP_MESSAGE
string|lang_map

Help message

MULTIPLE
boolean

Is the field multiple? Possible values:

  • Y — yes
  • N — no

Fields of type boolean cannot be multiple.

By default, N

MANDATORY
boolean

Is the field mandatory? Possible values:

  • Y — yes
  • N — no

By default, N

SHOW_FILTER
boolean

Should the field be shown in the filter? Possible values:

  • Y — yes
  • N — no

By default, N

SETTINGS
object

Additional field parameters. Each USER_TYPE_ID type has its own set of available settings, described below

LIST
uf_enum_element[]

List of possible values for the custom field of type enumeration, described below

By default, []

SORT
integer

Sort index. Must be greater than zero.

By default, 100

SHOW_IN_LIST
boolean

Should the custom field be shown in the list.

This parameter has no effect within crm.

Possible values:

  • Y — yes
  • N — no

By default, N

EDIT_IN_LIST
boolean

Allow user editing? Possible values:

  • Y — yes
  • N — no

By default, Y. The value N is not supported by all field types within crm

IS_SEARCHABLE
boolean

Are the field values searchable?

This parameter has no effect within crm.

Possible values:

  • Y — yes
  • N — no

By default, N

Parameter SETTINGS

Each type of custom field has its own set of additional settings. This method only supports those described below.

Name
type

Description

DEFAULT_VALUE
string

Default value.

By default ''

ROWS
integer

Number of rows in the input field. Must be greater than 0.

By default 1

Name
type

Description

DEFAULT_VALUE
integer

Default value

Name
type

Description

DEFAULT_VALUE
double

Default value

PRECISION
integer

Number precision. Must be greater than or equal to 0.

By default 2

Name
type

Description

DEFAULT_VALUE
integer

Default value, where 1 — yes, 0 — no.

Possible values:

  • >= 1 -> 1
  • <= 0 -> 0

By default 0

DISPLAY
string

Appearance. Possible values:

  • CHECKBOX — checkbox
  • RADIO — radio buttons
  • DROPDOWN — dropdown list

By default CHECKBOX

Name
type

Description

DEFAULT_VALUE
object

Default value.
Object format:

{
            VALUE: datetime|date,
            TYPE: 'NONE'|'NOW'|'FIXED',
        }
        

where:

  • VALUE — default value of type datetime or date
  • TYPE — type of default value:
    • NONE — do not set a default value
    • NOW — use the current time/date
    • FIXED — use the time/date from VALUE

Default value:

{
            VALUE: '',
            TYPE: 'NONE',
        }
        

Name
type

Description

DISPLAY
string

Appearance. Possible values:

  • LIST — list
  • UI — input list
  • CHECKBOX — checkboxes
  • DIALOG — entity selection dialog

By default LIST

LIST_HEIGHT

List height. Must be greater than 0.

Available only when DISPLAY = LIST or DISPLAY = UI.

By default 1

Name
type

Description

IBLOCK_TYPE_ID
string

Identifier of the information block type.

By default ''

IBLOCK_ID
string

Identifier of the information block.

By default 0

DEFAULT_VALUE
string

Default value.

By default ''

DISPLAY
string

Appearance. Possible values:

  • DIALOG — dialog
  • UI — input list
  • LIST — list
  • CHECKBOX — checkboxes

By default LIST

LIST_HEIGHT
integer

List height. Must be greater than 0.

By default 1

ACTIVE_FILTER
boolean

Should elements with the active flag be shown? Possible values:

  • Y — yes
  • N — no

By default N

Name
type

Description

ENTITY_TYPE
string

Identifier of the directory type.

Use crm.status.entity.types to find possible values.

By default ''

If none of the following options are provided, the binding to leads will be enabled by default LEAD = Y.

Name
type

Description

LEAD
boolean

Is the binding to Leads enabled? Possible values:

  • Y — yes
  • N — no

By default N

CONTACT
boolean

Is the binding to Contacts enabled? Possible values:

  • Y — yes
  • N — no

By default N

COMPANY
boolean

Is the binding to Companies enabled? Possible values:

  • Y — yes
  • N — no

By default N

DEAL
boolean

Is the binding to Deals enabled? Possible values:

  • Y — yes
  • N — no

By default N

Parameter LIST

Name
type

Description

VALUE
string

Value of the list element.

List elements with an empty or missing VALUE will be ignored

SORT
integer

Sort index. Must be greater than or equal to 0.

By default 0

DEF
boolean

Is the list element the default value? Possible values:

  • Y — yes
  • N — no

For a multiple field, multiple DEF = Y are allowed. For a non-multiple field, the first provided list element with DEF = Y will be considered default.

By default N

XML_ID
string

External code of the value. Must be unique within the list elements of the custom field

Code Examples

How to Use Examples in Documentation

Example of Creating a Custom Field of Type String

curl -X POST \
        -H "Content-Type: application/json" \
        -H "Accept: application/json" \
        -d '{"fields":{"LABEL":"Field Hello, World!","USER_TYPE_ID":"string","FIELD_NAME":"HELLO_WORLD","MULTIPLE":"Y","MANDATORY":"Y","SHOW_FILTER":"Y","SETTINGS":{"DEFAULT_VALUE":"Hello, World! Default value","ROWS":3},"SORT":1000,"EDIT_IN_LIST":"Y","LIST_FILTER_LABEL":"Hello, World! Filter","LIST_COLUMN_LABEL":{"en":"Hello, World! Column","de":"Hallo, Welt! Spalte"},"EDIT_FORM_LABEL":{"en":"Hello, World! Edit","de":"Hallo, Welt! Bearbeiten"},"ERROR_MESSAGE":{"en":"Hello, World! Error","de":"Hallo, Welt! Fehler"},"HELP_MESSAGE":{"en":"Hello, World! Help","de":"Hallo, Welt! Hilfe"}}}' \
        https://**put_your_bitrix24_address**/rest/**put_your_user_id_here**/**put_your_webhook_here**/crm.lead.userfield.add
        
curl -X POST \
        -H "Content-Type: application/json" \
        -H "Accept: application/json" \
        -d '{"fields":{"LABEL":"Field Hello, World!","USER_TYPE_ID":"string","FIELD_NAME":"HELLO_WORLD","MULTIPLE":"Y","MANDATORY":"Y","SHOW_FILTER":"Y","SETTINGS":{"DEFAULT_VALUE":"Hello, World! Default value","ROWS":3},"SORT":1000,"EDIT_IN_LIST":"Y","LIST_FILTER_LABEL":"Hello, World! Filter","LIST_COLUMN_LABEL":{"en":"Hello, World! Column","de":"Hallo, Welt! Spalte"},"EDIT_FORM_LABEL":{"en":"Hello, World! Edit","de":"Hallo, Welt! Bearbeiten"},"ERROR_MESSAGE":{"en":"Hello, World! Error","de":"Hallo, Welt! Fehler"},"HELP_MESSAGE":{"en":"Hello, World! Help","de":"Hallo, Welt! Hilfe"}},"auth":"**put_access_token_here**"}' \
        https://**put_your_bitrix24_address**/rest/crm.lead.userfield.add
        
try
        {
            const response = await $b24.callMethod(
                'crm.lead.userfield.add',
                {
                    fields: {
                        LABEL: 'Field Hello, World!',
                        USER_TYPE_ID: 'string',
                        FIELD_NAME: 'HELLO_WORLD',
                        MULTIPLE: 'Y',
                        MANDATORY: 'Y',
                        SHOW_FILTER: 'Y',
                        SETTINGS: {
                            DEFAULT_VALUE: 'Hello, World! Default value',
                            ROWS: 3,
                        },
                        SORT: 1000,
                        EDIT_IN_LIST: 'Y',
                        LIST_FILTER_LABEL: 'Hello, World! Filter',
                        LIST_COLUMN_LABEL: {
                            en: 'Hello, World! Column',
                            de: 'Hallo, Welt! Spalte',
                        },
                        EDIT_FORM_LABEL: {
                            en: 'Hello, World! Edit',
                            de: 'Hallo, Welt! Bearbeiten',
                        },
                        ERROR_MESSAGE: {
                            en: 'Hello, World! Error',
                            de: 'Hallo, Welt! Fehler',
                        },
                        HELP_MESSAGE: {
                            en: 'Hello, World! Help',
                            de: 'Hallo, Welt! Hilfe',
                        },
                    },
                }
            );
        
            console.info(response.getData().result);
        }
        catch (error)
        {
            console.error(error);
        }
        
try {
            $userfieldItemFields = [
                'FIELD_NAME' => 'HELLO_WORLD',
                'USER_TYPE_ID' => 'string',
                'SORT' => 1000,
                'MULTIPLE' => 'Y',
                'MANDATORY' => 'Y',
                'SHOW_FILTER' => 'Y',
                'EDIT_IN_LIST' => 'Y',
                'LIST_FILTER_LABEL' => 'Hello, World! Filter',
                'LIST_COLUMN_LABEL' => [
                    'en' => 'Hello, World! Column',
                    'de' => 'Hallo, Welt! Spalte',
                ],
                'EDIT_FORM_LABEL' => [
                    'en' => 'Hello, World! Edit',
                    'de' => 'Hallo, Welt! Bearbeiten',
                ],
                'ERROR_MESSAGE' => [
                    'en' => 'Hello, World! Error',
                    'de' => 'Hallo, Welt! Fehler',
                ],
                'HELP_MESSAGE' => [
                    'en' => 'Hello, World! Help',
                    'de' => 'Hallo, Welt! Hilfe',
                ],
                'SETTINGS' => [
                    'DEFAULT_VALUE' => 'Hello, World! Default value',
                    'ROWS' => 3,
                ],
            ];
        
            $result = $serviceBuilder
                ->getCRMScope()
                ->leadUserfield()
                ->add($userfieldItemFields);
        
            print($result->getId());
        } catch (Throwable $e) {
            print('Error: ' . $e->getMessage());
        }
        
BX24.callMethod(
            'crm.lead.userfield.add',
            {
                fields: {
                    LABEL: 'Field Hello, World!',
                    USER_TYPE_ID: 'string',
                    FIELD_NAME: 'HELLO_WORLD',
                    MULTIPLE: 'Y',
                    MANDATORY: 'Y',
                    SHOW_FILTER: 'Y',
                    SETTINGS: {
                        DEFAULT_VALUE: 'Hello, World! Default value',
                        ROWS: 3,
                    },
                    SORT: 1000,
                    EDIT_IN_LIST: 'Y',
                },
            },
            (result) => {
                result.error()
                    ? console.error(result.error())
                    : console.info(result.data());
            }
        );
        
require_once('crest.php');
        
        $result = CRest::call(
            'crm.lead.userfield.add',
            [
                'fields' => [
                    'LABEL' => 'Field Hello, World!',
                    'USER_TYPE_ID' => 'string',
                    'FIELD_NAME' => 'HELLO_WORLD',
                    'MULTIPLE' => 'Y',
                    'MANDATORY' => 'Y',
                    'SHOW_FILTER' => 'Y',
                    'SETTINGS' => [
                        'DEFAULT_VALUE' => 'Hello, World! Default value',
                        'ROWS' => 3,
                    ],
                    'SORT' => 1000,
                    'EDIT_IN_LIST' => 'Y',
                ]
            ]
        );
        
        echo '<PRE>';
        print_r($result);
        echo '</PRE>';
        

Example of Creating a Custom Field of Type List

curl -X POST \
        -H "Content-Type: application/json" \
        -H "Accept: application/json" \
        -d '{"fields":{"LABEL":"Custom Field (List)","USER_TYPE_ID":"enumeration","FIELD_NAME":"ENUMERATION_EXAMPLE","MULTIPLE":"N","MANDATORY":"N","SHOW_FILTER":"Y","LIST":[{"VALUE":"List Item #1","DEF":"Y","XML_ID":"XML_ID_1","SORT":100},{"VALUE":"List Item #2","XML_ID":"XML_ID_2","SORT":200},{"VALUE":"List Item #3","XML_ID":"XML_ID_3","SORT":300},{"VALUE":"List Item #4","XML_ID":"XML_ID_4","SORT":400}],"SETTINGS":{"DISPLAY":"UI","LIST_HEIGHT":2},"SORT":2000}}' \
        https://**put_your_bitrix24_address**/rest/**put_your_user_id_here**/**put_your_webhook_here**/crm.lead.userfield.add
        
curl -X POST \
        -H "Content-Type: application/json" \
        -H "Accept: application/json" \
        -d '{"fields":{"LABEL":"Custom Field (List)","USER_TYPE_ID":"enumeration","FIELD_NAME":"ENUMERATION_EXAMPLE","MULTIPLE":"N","MANDATORY":"N","SHOW_FILTER":"Y","LIST":[{"VALUE":"List Item #1","DEF":"Y","XML_ID":"XML_ID_1","SORT":100},{"VALUE":"List Item #2","XML_ID":"XML_ID_2","SORT":200},{"VALUE":"List Item #3","XML_ID":"XML_ID_3","SORT":300},{"VALUE":"List Item #4","XML_ID":"XML_ID_4","SORT":400}],"SETTINGS":{"DISPLAY":"UI","LIST_HEIGHT":2},"SORT":2000},"auth":"**put_access_token_here**"}' \
        https://**put_your_bitrix24_address**/rest/crm.lead.userfield.add
        
try
        {
            const response = await $b24.callMethod(
                'crm.lead.userfield.add',
                {
                    fields: {
                        LABEL: 'Custom Field (List)',
                        USER_TYPE_ID: 'enumeration',
                        FIELD_NAME: 'ENUMERATION_EXAMPLE',
                        MULTIPLE: 'N',
                        MANDATORY: 'N',
                        SHOW_FILTER: 'Y',
                        LIST: [
                            { VALUE: 'List Item #1', DEF: 'Y', XML_ID: 'XML_ID_1', SORT: 100 },
                            { VALUE: 'List Item #2', XML_ID: 'XML_ID_2', SORT: 200 },
                            { VALUE: 'List Item #3', XML_ID: 'XML_ID_3', SORT: 300 },
                            { VALUE: 'List Item #4', XML_ID: 'XML_ID_4', SORT: 400 },
                        ],
                        SETTINGS: {
                            DISPLAY: 'UI',
                            LIST_HEIGHT: 2,
                        },
                        SORT: 2000,
                    },
                }
            );
        
            console.info(response.getData().result);
        }
        catch (error)
        {
            console.error(error);
        }
        
try {
            $userfieldItemFields = [
                'LABEL' => 'Custom Field (List)',
                'USER_TYPE_ID' => 'enumeration',
                'FIELD_NAME' => 'ENUMERATION_EXAMPLE',
                'MULTIPLE' => 'N',
                'MANDATORY' => 'N',
                'SHOW_FILTER' => 'Y',
                'LIST' => [
                    ['VALUE' => 'List Item #1', 'DEF' => 'Y', 'XML_ID' => 'XML_ID_1', 'SORT' => 100],
                    ['VALUE' => 'List Item #2', 'XML_ID' => 'XML_ID_2', 'SORT' => 200],
                    ['VALUE' => 'List Item #3', 'XML_ID' => 'XML_ID_3', 'SORT' => 300],
                    ['VALUE' => 'List Item #4', 'XML_ID' => 'XML_ID_4', 'SORT' => 400],
                ],
                'SETTINGS' => ['DISPLAY' => 'UI', 'LIST_HEIGHT' => 2],
                'SORT' => 2000,
            ];
        
            $result = $serviceBuilder
                ->getCRMScope()
                ->leadUserfield()
                ->add($userfieldItemFields);
        
            print($result->getId());
        } catch (Throwable $e) {
            print('Error: ' . $e->getMessage());
        }
        
BX24.callMethod(
            'crm.lead.userfield.add',
            {
                fields: {
                    LABEL: 'Custom Field (List)',
                    USER_TYPE_ID: 'enumeration',
                    FIELD_NAME: 'ENUMERATION_EXAMPLE',
                    MULTIPLE: 'N',
                    MANDATORY: 'N',
                    SHOW_FILTER: 'Y',
                    LIST: [
                        { VALUE: 'List Item #1', DEF: 'Y', XML_ID: 'XML_ID_1', SORT: 100 },
                        { VALUE: 'List Item #2', XML_ID: 'XML_ID_2', SORT: 200 },
                        { VALUE: 'List Item #3', XML_ID: 'XML_ID_3', SORT: 300 },
                        { VALUE: 'List Item #4', XML_ID: 'XML_ID_4', SORT: 400 },
                    ],
                    SETTINGS: { DISPLAY: 'UI', LIST_HEIGHT: 2 },
                    SORT: 2000,
                },
            },
            (result) => {
                result.error()
                    ? console.error(result.error())
                    : console.info(result.data());
            }
        );
        
require_once('crest.php');
        
        $result = CRest::call(
            'crm.lead.userfield.add',
            [
                'fields' => [
                    'LABEL' => 'Custom Field (List)',
                    'USER_TYPE_ID' => 'enumeration',
                    'FIELD_NAME' => 'ENUMERATION_EXAMPLE',
                    'MULTIPLE' => 'N',
                    'MANDATORY' => 'N',
                    'SHOW_FILTER' => 'Y',
                    'LIST' => [
                        ['VALUE' => 'List Item #1', 'DEF' => 'Y', 'XML_ID' => 'XML_ID_1', 'SORT' => 100],
                        ['VALUE' => 'List Item #2', 'XML_ID' => 'XML_ID_2', 'SORT' => 200],
                        ['VALUE' => 'List Item #3', 'XML_ID' => 'XML_ID_3', 'SORT' => 300],
                        ['VALUE' => 'List Item #4', 'XML_ID' => 'XML_ID_4', 'SORT' => 400],
                    ],
                    'SETTINGS' => [
                        'DISPLAY' => 'UI',
                        'LIST_HEIGHT' => 2,
                    ],
                    'SORT' => 2000,
                ]
            ]
        );
        
        echo '<PRE>';
        print_r($result);
        echo '</PRE>';
        

Response Handling

HTTP Status: 200

{
            "result": 6997,
            "time": {
                "start": 1753789240.8146,
                "finish": 1753789241.058695,
                "duration": 0.2440950870513916,
                "processing": 0.19217395782470703,
                "date_start": "2025-07-29T14:40:40+02:00",
                "date_finish": "2025-07-29T14:40:41+02:00",
                "operating_reset_at": 1753789840,
                "operating": 0.19216084480285645
            }
        }
        

Returned Data

Name
type

Description

result
integer

Root element of the response, contains the identifier of the created custom field

time
time

Information about the request execution time

Error Handling

HTTP Status: 400

{
            "error": "",
            "error_description": "The 'USER_TYPE_ID' field is not found."
        }
        

Name
type

Description

error
string

String error code. It may consist of digits, Latin letters, and underscores

error_description
error_description

Textual description of the error. The description is not intended to be shown to the end user in its raw form

Possible Error Codes

Code

Description

Value

400

The 'FIELD_NAME' field is not found

Either an empty FIELD_NAME was provided, or it was not provided at all

400

Field name is too long (more than 50 characters).

The provided FIELD_NAME contains more than 50 characters

400

Field name contains invalid characters. Allowed are: A-Z, 0-9, and _.

The provided FIELD_NAME contains invalid characters

400

The 'USER_TYPE_ID' field is not found

Either an empty USER_TYPE_ID was provided, or it was not provided at all

400

Invalid user type specified

The provided USER_TYPE_ID does not exist

400

List item with XML_ID='XML_ID' already exists

The provided XML_ID values in the list items are not unique

Continue Learning