Create a new contact crm.contact.add

Scope: crm

Who can execute the method: any user with "add|import" access permission for contacts

Method Development Stopped

The method crm.contact.add continues to function, but there is a more relevant alternative crm.item.add.

The method crm.contact.add creates a new contact.

Method Parameters

Name
type

Description

fields
object

Object format:

{
            field_1: value_1,
            field_2: value_2,
            ...,
            field_n: value_n,
        }
        

where:

  • field_n — field name
  • value_n — field value

The list of available fields is described below.

An incorrect field in fields will be ignored

params
object

Object containing a set of additional parameters.

The structure and possible values are described below

Parameter fields

Name
type

Description

HONORIFIC
crm_status

Salutation.

The list of available salutation types can be obtained using the method crm.status.list with the filter { ENTITY_ID: "HONORIFIC" }.

Default — the first available salutation type

NAME
string

First name

SECOND_NAME
string

Middle name

LAST_NAME
string

Last name

PHOTO
file

Photo

BIRTHDATE
date

Date of birth

TYPE_ID
crm_status

Contact type.

The list of available contact types can be obtained using the method crm.status.list with the filter { ENTITY_ID: "CONTACT_TYPE" }.

Default — the first available contact type

SOURCE_ID
crm_status

Source.

The list of available source types can be obtained using the method crm.status.list with the filter { ENTITY_ID: "SOURCE" }.

Default — the first available source type

SOURCE_DESCRIPTION
string

Additional information about the source

POST
string

Position

COMMENTS
string

Comment. Supports BB codes

OPENED
boolean

Is it available to everyone? Possible values:

  • Y — yes
  • N — no

Default Y. The default value can be changed in CRM settings

EXPORT
boolean

Is the contact included in the export? Possible values:

  • Y — yes
  • N — no

Default Y

ASSIGNED_BY_ID
user

Identifier of the user responsible for the element.

Default — the identifier of the user calling the method

COMPANY_ID
crm_company

Identifier of the main company for the contact.

The list of companies can be obtained using the method crm.item.list with entityTypeId = 4

COMPANY_IDS
crm_company[]

Array of identifiers of companies to which the contact is linked.

The list of companies can be obtained using the method crm.item.list with entityTypeId = 4

UTM_SOURCE
string

Advertising system (Google Ads, etc.)

UTM_MEDIUM
string

Traffic type. Possible values:

  • CPC — ads
  • CPM — banners

UTM_CAMPAIGN
string

Advertising campaign designation

UTM_CONTENT
string

Campaign content. For example, for contextual ads

UTM_TERM
string

Campaign search condition. For example, keywords for contextual advertising

TRACE
string

Information for Sales Intelligence

PHONE
crm_multifield[]

Phone

EMAIL
crm_multifield[]

E-mail

WEB
crm_multifield[]

Website

IM
crm_multifield[]

Messenger

LINK
crm_multifield[]

Links. Service field

UF_...

Custom fields. For example, UF_CRM_25534736.

Depending on the account settings, contacts may have a set of custom fields of specific types.

You can add a custom field to a contact using the method crm.contact.userfield.add

PARENT_ID_...

Relationship fields.

If there are SPAs related to contacts in the account, there is a field for each such SPA that stores the relationship between that SPA and the contact. The field itself stores the identifier of the element of that SPA.

For example, the field PARENT_ID_153 — relationship with the SPA entityTypeId=153. It stores the identifier of the element of that SPA related to the current contact

Fields for linking with external data sources

If the contact is created by an external system, then:

  • the field ORIGINATOR_ID stores the string identifier of that system
  • the field ORIGIN_ID stores the string identifier of the contact in that external system
  • the field ORIGIN_VERSION stores the version of the contact data in that external system

Name
type

Description

ORIGINATOR_ID
string

Identifier of the external system that is the source of data about this contact

ORIGIN_ID
string

Version of the contact data in the external system. Used to protect data from accidental overwriting by the external system.

If the data was imported and not changed in the external system, such data can be edited in CRM without fear that the next export will overwrite the data

ORIGIN_VERSION
string

Original version

Import

The fields are available for filling when the parameter IMPORT = 'Y' is passed in the params parameter.

Name
type

Description

DATE_CREATE
datetime

Creation date.

Available when IMPORT = Y is passed in params.

Cannot be earlier than the creation date of the last created contact

DATE_MODIFY
datetime

Modification date.

Available when IMPORT = Y is passed in params

CREATED_BY_ID
user

Created by.

Available when IMPORT = Y is passed in params

MODIFY_BY_ID
user

Modified by.

Available when IMPORT = Y is passed in params

Deprecated fields

Address fields in the contact are deprecated and are only used in compatibility mode. To work with the address, use requisites.

Name
type

Description

ADDRESS
string

Address

ADDRESS_2
string

Second line of the address

ADDRESS_CITY
string

City

ADDRESS_POSTAL_CODE
string

Postal code

ADDRESS_REGION
string

Region

ADDRESS_PROVINCE
string

Province

ADDRESS_COUNTRY
string

Country

ADDRESS_COUNTRY_CODE
string

Country code

ADDRESS_LOC_ADDR_ID
integer

Location address identifier

Parameter params

Name
type

Description

REGISTER_SONET_EVENT
boolean

Should the event of adding a contact be registered in the live feed? Possible values:

  • Y — yes
  • N — no

Default N

IMPORT
boolean

Is import mode enabled? Possible values:

  • Y — yes

To pass the value No, you must either not pass the parameter at all or pass the value 0, ''

Default No

Code Examples

How to Use Examples in Documentation

curl -X POST \
        -H "Content-Type: application/json" \
        -H "Accept: application/json" \
        -d '{"FIELDS":{"HONORIFIC":"HNR_RU_1","NAME":"John","SECOND_NAME":"Nicholas","LAST_NAME":"Mitchell","PHOTO":{"fileData":"**put_photo_data_here**"},"BIRTHDATE":"11.11.2001","TYPE_ID":"PARTNER","SOURCE_ID":"WEB","SOURCE_DESCRIPTION":"*Additional information about the source*","POST":"Administrator","COMMENTS":"**put_comment_here**","OPENED":"Y","EXPORT":"N","ASSIGNED_BY_ID":6,"COMPANY_ID":12,"COMPANY_IDS":[12,13,15],"UTM_SOURCE":"google","UTM_MEDIUM":"CPC","UTM_CAMPAIGN":"summer_sale","UTM_CONTENT":"header_banner","UTM_TERM":"discount","PHONE":[{"VALUE":"+12333333555","VALUE_TYPE":"WORK"},{"VALUE":"+15599888666","VALUE_TYPE":"HOME"}],"EMAIL":[{"VALUE":"mitchell@example.mailing","VALUE_TYPE":"MAILING"},{"VALUE":"mitchell@example.work","VALUE_TYPE":"WORK"}],"UF_CRM_1720697698689":"Example value of a custom field with type \"String\"","PARENT_ID_1224":12}}' \
        https://**put_your_bitrix24_address**/rest/**put_your_user_id_here**/**put_your_webhook_here**/crm.contact.add
        
curl -X POST \
        -H "Content-Type: application/json" \
        -H "Accept: application/json" \
        -d '{"FIELDS":{"HONORIFIC":"HNR_RU_1","NAME":"John","SECOND_NAME":"Nicholas","LAST_NAME":"mitchell","PHOTO":{"fileData":"**put_photo_data_here**"},"BIRTHDATE":"11.11.2001","TYPE_ID":"PARTNER","SOURCE_ID":"WEB","SOURCE_DESCRIPTION":"*Additional information about the source*","POST":"Administrator","COMMENTS":"**put_comment_here**","OPENED":"Y","EXPORT":"N","ASSIGNED_BY_ID":6,"COMPANY_ID":12,"COMPANY_IDS":[12,13,15],"UTM_SOURCE":"google","UTM_MEDIUM":"CPC","UTM_CAMPAIGN":"summer_sale","UTM_CONTENT":"header_banner","UTM_TERM":"discount","PHONE":[{"VALUE":"+12333333555","VALUE_TYPE":"WORK"},{"VALUE":"+15599888666","VALUE_TYPE":"HOME"}],"EMAIL":[{"VALUE":"mitchell@example.mailing","VALUE_TYPE":"MAILING"},{"VALUE":"mitchell@example.work","VALUE_TYPE":"WORK"}],"UF_CRM_1720697698689":"Example value of a custom field with type \"String\"","PARENT_ID_1224":12},"auth":"**put_access_token_here**"}' \
        https://**put_your_bitrix24_address**/rest/crm.contact.add
        
try
        {
        	const response = await $b24.callMethod(
        		'crm.contact.add',
        		{
        			fields: {
        				HONORIFIC: "HNR_RU_1",
        				NAME: "John",
        				SECOND_NAME: "Nicholas",
        				LAST_NAME: "Mitchell",
        				PHOTO: {
        					fileData: document.getElementById('photo'),
        				},
        				BIRTHDATE: '11.11.2001',
        				TYPE_ID: "PARTNER",
        				SOURCE_ID: "WEB",
        				SOURCE_DESCRIPTION: "*Additional information about the source*",
        				POST: "Administrator",
        				COMMENTS: `
                            Example comment inside the contact
        
                            [B]Bold text[/B]
                            [I]Italic[/I]
                            [U]Underlined[/U]
                            [S]Strikethrough[/S]
                            [B][I][U][S]Mix[/S][/U][/I][/B]
        
                            [LIST]
                            [*]List item #1
                            [*]List item #2
                            [*]List item #3
                            [/LIST]
        
                            [LIST=1]
                            [*]Numbered list item #1
                            [*]Numbered list item #2
                            [*]Numbered list item #3
                            [/LIST]
                        `,
        				OPENED: "Y",
        				EXPORT: "N",
        				ASSIGNED_BY_ID: 6,
        				COMPANY_ID: 12,
        				COMPANY_IDS: [12, 13, 15],
        				UTM_SOURCE: "google",
        				UTM_MEDIUM: "CPC",
        				UTM_CAMPAIGN: "summer_sale",
        				UTM_CONTENT: "header_banner",
        				UTM_TERM: "discount",
        				PHONE: [
        					{
        						VALUE: "+12333333555",
        						VALUE_TYPE: "WORK",
        					},
        					{
        						VALUE: "+15599888666",
        						VALUE_TYPE: "HOME",
        					}
        				],
        				EMAIL: [
        					{
        						VALUE: "mitchellv@example.mailing",
        						VALUE_TYPE: "MAILING",
        					},
        					{
        						VALUE: "mitchell@example.work",
        						VALUE_TYPE: "WORK",
        					}
        				],
        				UF_CRM_1720697698689: "Example value of a custom field with type \"String\"",
        				PARENT_ID_1224: 12,
        			},
        		}
        	);
        	
        	const result = response.getData().result;
        	result.error()
        		? console.error(result.error())
        		: console.info(result)
        	;
        }
        catch( error )
        {
        	console.error(error);
        }
        
try {
            $response = $b24Service
                ->core
                ->call(
                    'crm.contact.add',
                    [
                        'fields' => [
                            'HONORIFIC' => 'HNR_RU_1',
                            'NAME' => 'John',
                            'SECOND_NAME' => 'Nicholas',
                            'LAST_NAME' => 'Mitchell',
                            'PHOTO' => [
                                'fileData' => document.getElementById('photo'),
                            ],
                            'BIRTHDATE' => '11.11.2001',
                            'TYPE_ID' => 'PARTNER',
                            'SOURCE_ID' => 'WEB',
                            'SOURCE_DESCRIPTION' => '*Additional information about the source*',
                            'POST' => 'Administrator',
                            'COMMENTS' => `
                                Example comment inside the contact
        
                                [B]Bold text[/B]
                                [I]Italic[/I]
                                [U]Underlined[/U]
                                [S]Strikethrough[/S]
                                [B][I][U][S]Mix[/S][/U][/I][/B]
        
                                [LIST]
                                [*]List item #1
                                [*]List item #2
                                [*]List item #3
                                [/LIST]
        
                                [LIST=1]
                                [*]Numbered list item #1
                                [*]Numbered list item #2
                                [*]Numbered list item #3
                                [/LIST]
                            `,
                            'OPENED' => 'Y',
                            'EXPORT' => 'N',
                            'ASSIGNED_BY_ID' => 6,
                            'COMPANY_ID' => 12,
                            'COMPANY_IDS' => [12, 13, 15],
                            'UTM_SOURCE' => 'google',
                            'UTM_MEDIUM' => 'CPC',
                            'UTM_CAMPAIGN' => 'summer_sale',
                            'UTM_CONTENT' => 'header_banner',
                            'UTM_TERM' => 'discount',
                            'PHONE' => [
                                [
                                    'VALUE' => '+12333333555',
                                    'VALUE_TYPE' => 'WORK',
                                ],
                                [
                                    'VALUE' => '+15599888666',
                                    'VALUE_TYPE' => 'HOME',
                                ]
                            ],
                            'EMAIL' => [
                                [
                                    'VALUE' => 'mitchell@example.mailing',
                                    'VALUE_TYPE' => 'MAILING',
                                ],
                                [
                                    'VALUE' => 'mitchell@example.work',
                                    'VALUE_TYPE' => 'WORK',
                                ]
                            ],
                            'UF_CRM_1720697698689' => 'Example value of a custom field with type "String"',
                            'PARENT_ID_1224' => 12,
                        ]
                    ]
                );
        
            $result = $response
                ->getResponseData()
                ->getResult();
        
            echo 'Success: ' . print_r($result, true);
            processData($result);
        
        } catch (Throwable $e) {
            error_log($e->getMessage());
            echo 'Error adding contact: ' . $e->getMessage();
        }
        
BX24.callMethod(
            'crm.contact.add',
            {
                fields: {
                    HONORIFIC: "HNR_RU_1",
                    NAME: "John",
                    SECOND_NAME: "Nicholas",
                    LAST_NAME: "Mitchell",
                    PHOTO: {
                        fileData: document.getElementById('photo'),
                    },
                    BIRTHDATE: '11.11.2001',
                    TYPE_ID: "PARTNER",
                    SOURCE_ID: "WEB",
                    SOURCE_DESCRIPTION: "*Additional information about the source*",
                    POST: "Administrator",
                    COMMENTS: `
                        Example comment inside the contact
        
                        [B]Bold text[/B]
                        [I]Italic[/I]
                        [U]Underlined[/U]
                        [S]Strikethrough[/S]
                        [B][I][U][S]Mix[/S][/U][/I][/B]
        
                        [LIST]
                        [*]List item #1
                        [*]List item #2
                        [*]List item #3
                        [/LIST]
        
                        [LIST=1]
                        [*]Numbered list item #1
                        [*]Numbered list item #2
                        [*]Numbered list item #3
                        [/LIST]
                    `,
                    OPENED: "Y",
                    EXPORT: "N",
                    ASSIGNED_BY_ID: 6,
                    COMPANY_ID: 12,
                    COMPANY_IDS: [12, 13, 15],
                    UTM_SOURCE: "google",
                    UTM_MEDIUM: "CPC",
                    UTM_CAMPAIGN: "summer_sale",
                    UTM_CONTENT: "header_banner",
                    UTM_TERM: "discount",
                    PHONE: [
                        {
                            VALUE: "+12333333555",
                            VALUE_TYPE: "WORK",
                        },
                        {
                            VALUE: "+15599888666",
                            VALUE_TYPE: "HOME",
                        }
                    ],
                    EMAIL: [
                        {
                            VALUE: "mitchell@example.mailing",
                            VALUE_TYPE: "MAILING",
                        },
                        {
                            VALUE: "mitchell@example.work",
                            VALUE_TYPE: "WORK",
                        }
                    ],
                    UF_CRM_1720697698689: "Example value of a custom field with type \"String\"",
                    PARENT_ID_1224: 12,
                },
            },
            (result) => {
                result.error()
                    ? console.error(result.error())
                    : console.info(result.data())
                ;
            },
        );
        
require_once('crest.php');
        
        $result = CRest::call(
            'crm.contact.add',
            [
                'FIELDS' => [
                    'HONORIFIC' => 'HNR_RU_1',
                    'NAME' => 'John',
                    'SECOND_NAME' => 'Nicholas',
                    'LAST_NAME' => 'Mitchell',
                    'PHOTO' => [
                        'fileData' => $_FILES['photo']
                    ],
                    'BIRTHDATE' => '11.11.2001',
                    'TYPE_ID' => 'PARTNER',
                    'SOURCE_ID' => 'WEB',
                    'SOURCE_DESCRIPTION' => '*Additional information about the source*',
                    'POST' => 'Administrator',
                    'COMMENTS' => `
                        Example comment inside the contact
        
                        [B]Bold text[/B]
                        [I]Italic[/I]
                        [U]Underlined[/U]
                        [S]Strikethrough[/S]
                        [B][I][U][S]Mix[/S][/U][/I][/B]
        
                        [LIST]
                        [*]List item #1
                        [*]List item #2
                        [*]List item #3
                        [/LIST]
        
                        [LIST=1]
                        [*]Numbered list item #1
                        [*]Numbered list item #2
                        [*]Numbered list item #3
                        [/LIST]
                    `,
                    'OPENED' => 'Y',
                    'EXPORT' => 'N',
                    'ASSIGNED_BY_ID' => 6,
                    'COMPANY_ID' => 12,
                    'COMPANY_IDS' => [12, 13, 15],
                    'UTM_SOURCE' => 'google',
                    'UTM_MEDIUM' => 'CPC',
                    'UTM_CAMPAIGN' => 'summer_sale',
                    'UTM_CONTENT' => 'header_banner',
                    'UTM_TERM' => 'discount',
                    'PHONE' => [
                        [
                            'VALUE' => '+12333333555',
                            'VALUE_TYPE' => 'WORK',
                        ],
                        [
                            'VALUE' => '+15599888666',
                            'VALUE_TYPE' => 'HOME',
                        ]
                    ],
                    'EMAIL' => [
                        [
                            'VALUE' => 'mitchell@example.mailing',
                            'VALUE_TYPE' => 'MAILING',
                        ],
                        [
                            'VALUE' => 'mitchell@example.work',
                            'VALUE_TYPE' => 'WORK',
                        ]
                    ],
                    'UF_CRM_1720697698689' => 'Example value of a custom field with type "String"',
                    'PARENT_ID_1224' => 12,
                ]
            ]
        );
        
        echo '<PRE>';
        print_r($result);
        echo '</PRE>';
        

Response Handling

HTTP status: 200

{
            "result": 46,
            "time": {
                "start": 1723713732.235658,
                "finish": 1723713733.742049,
                "duration": 1.5063910484313965,
                "processing": 1.1416668891906738,
                "date_start": "2024-08-15T11:22:12+02:00",
                "date_finish": "2024-08-15T11:22:13+02:00"
            }
        }
        

Returned Data

Name
type

Description

result
integer

Root element of the response, contains the identifier of the created contact

time
time

Information about the request execution time

Error Handling

HTTP status: 400

{
            "error": "",
            "error_description": "Parameter 'fields' must be array."
        }
        

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

-

Parameter 'fields' must be array

The parameter fields is not an object

-

Parameter 'params' must be array

The parameter params is not an object

-

Access denied

The user does not have permission to "Add" or "Import" contacts

-

Disk resource exhausted

ERROR_CORE

The field Work e-mail contains an invalid address

Statuses and System Error Codes

HTTP Status: 20x, 40x, 50x

The errors described below may occur when calling any method.

Status

Code
Error Message

Description

500

INTERNAL_SERVER_ERROR
Internal server error

An internal server error has occurred, please contact the server administrator or Bitrix24 technical support

500

ERROR_UNEXPECTED_ANSWER
Server returned an unexpected response

An internal server error has occurred, please contact the server administrator or Bitrix24 technical support

503

QUERY_LIMIT_EXCEEDED
Too many requests

The request intensity limit has been exceeded

405

ERROR_BATCH_METHOD_NOT_ALLOWED
Method is not allowed for batch usage

The current method is not allowed to be called using batch

400

ERROR_BATCH_LENGTH_EXCEEDED
Max batch length exceeded

The maximum length of parameters passed to the batch method has been exceeded

401

NO_AUTH_FOUND
Wrong authorization data

Invalid access token or webhook code

400

INVALID_REQUEST
Https required

The methods must be called using the HTTPS protocol

503

OVERLOAD_LIMIT
REST API is blocked due to overload

The REST API is blocked due to overload. This is a manual individual block, to remove it you need to contact Bitrix24 technical support

403

ACCESS_DENIED
REST API is available only on commercial plans

The REST API is available only on commercial plans

403

INVALID_CREDENTIALS
Invalid request credentials

The user whose access token or webhook was used to call the method lacks permissions

404

ERROR_MANIFEST_IS_NOT_AVAILABLE
Manifest is not available

The manifest is not available

403

insufficient_scope
The request requires higher privileges than provided by the webhook token

The request requires higher privileges than those provided by the webhook token

401

expired_token
The access token provided has expired

The provided access token has expired

403

user_access_error
The user does not have access to the application

The user does not have access to the application. This means that the application is installed, but the account administrator has allowed access to this application only for specific users

500

PORTAL_DELETED
Portal was deleted

The public part of the site is closed. To open the public part of the site on an on-premise installation, disable the option "Temporary closure of the public part of the site". Path to the setting: Desktop > Settings > Product Settings > Module Settings > Main Module > Temporary closure of the public part of the site

Continue Learning