Update Contact crm.contact.update
Scope:
crmWho can execute the method: any user with "edit" access permission for contacts
Method Development Stopped
The method crm.contact.update continues to function, but there is a more relevant alternative crm.item.update.
The method crm.contact.update updates an existing contact.
It is recommended to pass the complete set of address fields when updating the address.
Method Parameters
Required parameters are marked with *
|
Name |
Description |
|
id* |
Identifier of the contact to be changed. The identifier can be obtained using the methods |
|
fields* |
Object in the format:
where:
The list of available fields is described below. An incorrect field in Only those fields that need to be changed should be passed in |
|
params |
Object containing a set of additional parameters. The structure and possible values are described below |
Parameter fields
|
Name |
Description |
|
HONORIFIC |
Salutation. The list of available salutation types can be obtained using |
|
NAME |
First name |
|
SECOND_NAME |
Middle name |
|
LAST_NAME |
Last name |
|
PHOTO |
Photo |
|
BIRTHDATE |
Date of birth |
|
TYPE_ID |
Contact type. |
|
SOURCE_ID |
Source |
|
SOURCE_DESCRIPTION |
Additional information about the source |
|
POST |
Position |
|
COMMENTS |
Comment. Supports BB codes |
|
OPENED |
Is it available to everyone? Possible values:
|
|
EXPORT |
Is the contact participating in the export? Possible values:
|
|
ASSIGNED_BY_ID |
Identifier of the user responsible for the item |
|
COMPANY_ID |
Identifier of the main company for the contact. The list of companies can be obtained using the method |
|
COMPANY_IDS |
Array of identifiers of companies to which the contact is linked. The list of companies can be obtained using the method |
|
UTM_SOURCE |
Advertising system (Google Ads, etc.) |
|
UTM_MEDIUM |
Type of traffic. Possible values:
|
|
UTM_CAMPAIGN |
Advertising campaign designation |
|
UTM_CONTENT |
Content of the campaign. For example, for contextual ads |
|
UTM_TERM |
Search condition of the campaign. For example, keywords for contextual advertising |
|
PHONE |
Phone |
|
EMAIL |
|
|
WEB |
Website |
|
Messenger |
|
|
LINK |
Links. Service field |
|
UF_... |
Custom fields. For example, Depending on the account settings, contacts may have a set of custom fields of specific types. To change file fields, it is recommended to use the method crm.item.update. A custom field can be added to a contact using the method crm.contact.userfield.add |
|
PARENT_ID_... |
Relationship fields. If there are smart processes related to contacts in the account, there is a field for each such smart process that stores the relationship between this smart process and the contact. The field itself stores the identifier of the element of that smart process. For example, the field |
Fields for external data sources
If the contact was created by an external system, then:
- the field
ORIGINATOR_IDstores the string identifier of that system - the field
ORIGIN_IDstores the string identifier of the contact in that external system - the field
ORIGIN_VERSIONstores the version of the contact data in that external system
|
Name |
Description |
|
ORIGINATOR_ID |
Identifier of the external system that is the source of data about this contact |
|
ORIGIN_ID |
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, then such data can be edited in CRM without fear that the next export will lead to data overwriting |
|
ORIGIN_VERSION |
Version of the original |
Deprecated fields
Address fields in the contact are deprecated and are only used in compatibility mode. To work with the address, use requisites.
|
Name |
Description |
|
ADDRESS |
Address |
|
ADDRESS_2 |
Second line of the address |
|
ADDRESS_CITY |
City |
|
ADDRESS_POSTAL_CODE |
Postal code |
|
ADDRESS_REGION |
Region |
|
ADDRESS_PROVINCE |
Province |
|
ADDRESS_COUNTRY |
Country |
|
ADDRESS_COUNTRY_CODE |
Country code |
|
ADDRESS_LOC_ADDR_ID |
Identifier of the location address |
Parameter params
|
Name |
Description |
|
REGISTER_SONET_EVENT |
Should the update event of the contact be registered in the activity stream? Possible values:
Default is |
|
REGISTER_HISTORY_EVENT |
Should the update of the contact be registered in the history? Possible values:
Default is |
Code Examples
How to Use Examples in Documentation
Update contact with id = 43
curl -X POST \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d '{"ID":43,"FIELDS":{"NAME":"John","BIRTHDATE":"11.11.1999","TYPE_ID":"RECOMMENDATION","SOURCE_ID":"WEB","POST":"Network Administrator","COMMENTS":"New comment","OPENED":"N","EXPORT":"Y","ASSIGNED_BY_ID":1,"COMPANY_ID":12,"COMPANY_IDS":[13,15],"UF_CRM_1720697698689":"Example of a new value for a custom field of type \"String\"","PARENT_ID_1224":14},"PARAMS":{"REGISTER_SONET_EVENT":"N","REGISTER_HISTORY_EVENT":"N"}}' \
https://**put_your_bitrix24_address**/rest/**put_your_user_id_here**/**put_your_webhook_here**/crm.contact.update
curl -X POST \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d '{"ID":43,"FIELDS":{"NAME":"John","BIRTHDATE":"11.11.1999","TYPE_ID":"RECOMMENDATION","SOURCE_ID":"WEB","POST":"Network Administrator","COMMENTS":"New comment","OPENED":"N","EXPORT":"Y","ASSIGNED_BY_ID":1,"COMPANY_ID":12,"COMPANY_IDS":[13,15],"UF_CRM_1720697698689":"Example of a new value for a custom field of type \"String\"","PARENT_ID_1224":14},"PARAMS":{"REGISTER_SONET_EVENT":"N","REGISTER_HISTORY_EVENT":"N"},"auth":"**put_access_token_here**"}' \
https://**put_your_bitrix24_address**/rest/crm.contact.update
try
{
const response = await $b24.callMethod(
'crm.contact.update',
{
id: 43,
fields: {
NAME: "John",
BIRTHDATE: '11.11.1999',
TYPE_ID: "RECOMMENDATION",
SOURCE_ID: "WEB",
POST: "Network Administrator",
COMMENTS: "New comment",
OPENED: "N",
EXPORT: "Y",
ASSIGNED_BY_ID: 1,
COMPANY_ID: 12,
COMPANY_IDS: [13, 15],
UF_CRM_1720697698689: "Example of a new value for a custom field of type \"String\"",
PARENT_ID_1224: 14,
},
params: {
REGISTER_SONET_EVENT: "N",
REGISTER_HISTORY_EVENT: "N",
},
}
);
const result = response.getData().result;
result.error()
? console.error(result.error())
: console.info(result)
;
}
catch( error )
{
console.error('Error:', error);
}
try {
$contactId = 123; // Example contact ID
$fields = [
'NAME' => 'John',
'LAST_NAME' => 'Doe',
'BIRTHDATE' => (new DateTime('1990-01-01'))->format(DateTime::ATOM),
'PHONE' => '123456789',
'EMAIL' => 'john.doe@example.com',
'ADDRESS' => '123 Main St',
'ADDRESS_CITY' => 'Anytown',
'ADDRESS_COUNTRY' => 'USA',
];
$params = [
'REGISTER_SONET_EVENT' => 'Y',
];
$result = $serviceBuilder
->getCRMScope()
->contact()
->update($contactId, $fields, $params);
if ($result->isSuccess()) {
print($result->getCoreResponse()->getResponseData()->getResult()[0]);
} else {
print('Update failed.');
}
} catch (Throwable $e) {
print('Error: ' . $e->getMessage());
}
BX24.callMethod(
'crm.contact.update',
{
id: 43,
fields: {
NAME: "John",
BIRTHDATE: '11.11.1999',
TYPE_ID: "RECOMMENDATION",
SOURCE_ID: "WEB",
POST: "Network Administrator",
COMMENTS: "New comment",
OPENED: "N",
EXPORT: "Y",
ASSIGNED_BY_ID: 1,
COMPANY_ID: 12,
COMPANY_IDS: [13, 15],
UF_CRM_1720697698689: "Example of a new value for a custom field of type \"String\"",
PARENT_ID_1224: 14,
},
params: {
REGISTER_SONET_EVENT: "N",
REGISTER_HISTORY_EVENT: "N",
},
},
(result) => {
result.error()
? console.error(result.error())
: console.info(result.data())
;
},
);
require_once('crest.php');
$result = CRest::call(
'crm.contact.update',
[
'ID' => 43,
'FIELDS' => [
'NAME' => 'John',
'BIRTHDATE' => '11.11.1999',
'TYPE_ID' => 'RECOMMENDATION',
'SOURCE_ID' => 'WEB',
'POST' => 'Network Administrator',
'COMMENTS' => 'New comment',
'OPENED' => 'N',
'EXPORT' => 'Y',
'ASSIGNED_BY_ID' => 1,
'COMPANY_ID' => 12,
'COMPANY_IDS' => [13, 15],
'UF_CRM_1720697698689' => 'Example of a new value for a custom field of type "String"',
'PARENT_ID_1224' => 14,
],
'PARAMS' => [
'REGISTER_SONET_EVENT' => 'N',
'REGISTER_HISTORY_EVENT' => 'N',
]
]
);
echo '<PRE>';
print_r($result);
echo '</PRE>';
Working with Multiple Fields
Update a Multiple Field
To overwrite an existing value of a multiple field, pass the ID of the field you want to change and its new value/type.
Suppose there are the following values for the PHONE field:
[
{
"ID": "222",
"VALUE_TYPE": "WORK",
"VALUE": "111111",
"TYPE_ID": "PHONE"
},
{
"ID": "223",
"VALUE_TYPE": "WORK",
"VALUE": "222222",
"TYPE_ID": "PHONE"
},
{
"ID": "224",
"VALUE_TYPE": "WORK",
"VALUE": "333333",
"TYPE_ID": "PHONE"
}
]
To change the value of the phone with ID = 223, pass the following fields parameter:
{
"fields": {
"PHONE": [
{
"ID": 223,
"VALUE": "444444",
"VALUE_TYPE": "MOBILE"
}
]
}
}
Delete a Single Value from a Multiple Field
To delete one of the values from a multiple field, pass their identifiers and either the parameter DELETE = 'Y' or an empty VALUE.
Suppose there are the following values for the PHONE field:
[
{
"ID": "222",
"VALUE_TYPE": "WORK",
"VALUE": "111111",
"TYPE_ID": "PHONE"
},
{
"ID": "223",
"VALUE_TYPE": "WORK",
"VALUE": "222222",
"TYPE_ID": "PHONE"
},
{
"ID": "224",
"VALUE_TYPE": "WORK",
"VALUE": "333333",
"TYPE_ID": "PHONE"
},
{
"ID": "225",
"VALUE_TYPE": "WORK",
"VALUE": "44444",
"TYPE_ID": "PHONE"
}
]
Let's consider ways to delete all values except for the phone with ID = 225:
{
"fields": {
"PHONE": [
{
"ID": 222,
"DELETE": "Y"
},
{
"ID": 223,
"VALUE": ""
},
{
"ID": 224
}
]
}
}
As a result, the following will remain:
[
{
"ID": "225",
"VALUE_TYPE": "WORK",
"VALUE": "44444",
"TYPE_ID": "PHONE"
}
]
Add a New Value to a Multiple Field
To add a new value, simply enter it. Existing values will not be changed.
Example of adding a new value 55555:
{
"fields": {
"PHONE": [
{
"VALUE": "55555",
"VALUE_TYPE": "WORK"
}
]
}
}
Response Handling
HTTP status: 200
{
"result": true,
"time": {
"start": 1723820393.459406,
"finish": 1723820396.129949,
"duration": 2.6705431938171387,
"processing": 2.1193439960479736,
"date_start": "2024-08-16T16:59:53+02:00",
"date_finish": "2024-08-16T16:59:56+02:00"
}
}
Returned Data
|
Name |
Description |
|
result |
Root element of the response, |
|
time |
Information about the execution time of the request |
Error Handling
HTTP status: 400
{
"error": "",
"error_description": "Contact is not found"
}
|
Name |
Description |
|
error |
String error code. It may consist of digits, Latin letters, and underscores |
|
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 |
|
|
|
The |
|
|
|
The |
|
|
|
The user does not have permission to "Edit" contacts |
|
|
Disk resource exhausted |
|
|
|
The field |
Statuses and System Error Codes
HTTP Status: 20x, 40x, 50x
The errors described below may occur when calling any method.
|
Status |
Code |
Description |
|
|
|
An internal server error has occurred, please contact the server administrator or Bitrix24 technical support |
|
|
|
An internal server error has occurred, please contact the server administrator or Bitrix24 technical support |
|
|
|
The request intensity limit has been exceeded |
|
|
|
The current method is not allowed to be called using batch |
|
|
|
The maximum length of parameters passed to the batch method has been exceeded |
|
|
|
Invalid access token or webhook code |
|
|
|
The methods must be called using the HTTPS protocol |
|
|
|
The REST API is blocked due to overload. This is a manual individual block, to remove it you need to contact Bitrix24 technical support |
|
|
|
The REST API is available only on commercial plans |
|
|
|
The user whose access token or webhook was used to call the method lacks permissions |
|
|
|
The manifest is not available |
|
|
|
The request requires higher privileges than those provided by the webhook token |
|
|
|
The provided access token has expired |
|
|
|
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 |
|
|
|
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
- Create a new contact crm.contact.add
- Get Contact by Id crm.contact.get
- Get the list of contacts crm.contact.list
- Delete contact crm.contact.delete
- Get Contact Fields crm.contact.fields
- How to Change or Delete Phone Numbers and Emails