Update Deal crm.deal.update

Scope: crm

Who can execute the method: any user with "edit" access permission for deals

Method Development Stopped

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

The method crm.deal.update updates an existing deal.

Method Parameters

Required parameters are marked with *

Name
type

Description

id*
integer

Identifier of the deal.

The identifier can be obtained using the methods crm.deal.list or crm.deal.add

fields
object

Object format:

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

where:

  • field_n — field name
  • value_n — new field value

The list of available fields is described below.

An incorrect field in fields will be ignored.

Only those fields that need to be changed should be passed in fields

params
object

Set of additional parameters (detailed description)

Parameter fields

Name
type

Description

TITLE
string

Title of the deal

TYPE_ID
crm_status

String identifier of the deal type.

The list of available deal types can be obtained using the method crm.status.list with the filter { ENTITY_ID: 'DEAL_TYPE' }

STAGE_ID
crm_status

Stage of the deal.

The list of available stages can be obtained using the method crm.status.list with the filter:

  • { ENTITY_ID: "DEAL_STAGE" } — if the deal is in the general Sales Funnel
  • { ENTITY_ID: "DEAL_STAGE_{categoryId}" } — if the deal is not in the general Sales Funnel, where categoryId is the identifier of the funnel and equals CATEGORY_ID of the deal.

If it is necessary to change the funnel of the deal, use the method crm.item.update, with the entityTypeId of the deal being 2

IS_RECURRING
char

Indicates whether the deal is a recurring deal template. Possible values:

  • Y — yes
  • N — no

IS_RETURN_CUSTOMER
char

Indicates whether the deal is a repeat deal. Possible values:

  • Y — yes
  • N — no

IS_REPEATED_APPROACH
char

Indicates whether the deal is a repeated approach. Possible values:

  • Y — yes
  • N — no

PROBABILITY
integer

Probability, %

CURRENCY_ID
crm_currency

Currency.

The list of available currencies can be obtained using the method crm.currency.list

OPPORTUNITY
double

Amount

IS_MANUAL_OPPORTUNITY
char

Indicates whether manual calculation mode is enabled. Possible values:

  • Y — yes
  • N — no

TAX_VALUE
double

Tax amount

COMPANY_ID
crm_company

Identifier of the company associated with the deal.

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

CONTACT_ID
crm_contact

Contact. Deprecated

CONTACT_IDS
crm_contact[]

List of contacts associated with the deal. The field is completely replaced.

To change individual related contacts, use the methods crm.deal.contact.items.*.

BEGINDATE
date

Start date

CLOSEDATE
date

End date

OPENED
char

Is the deal available to everyone. Possible values:

  • Y — yes
  • N — no

CLOSED
char

Is the deal closed. Possible values:

  • Y — yes
  • N — no

COMMENTS
string

Comment. Supports bb-codes

ASSIGNED_BY_ID
user

Responsible person

SOURCE_ID
crm_status

String identifier of the source type.

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

SOURCE_DESCRIPTION
string

Additional information about the source

ADDITIONAL_INFO
string

Additional information

LOCATION_ID
location

Client's location. System field

ORIGINATOR_ID
string

Identifier of the data source.

Used only for linking to an external source

ORIGIN_ID
string

Identifier of the element in the data source.

Used only for linking to an external source

UTM_SOURCE
string

Advertising system (Google-Adwords and others)

UTM_MEDIUM
string

Type of traffic. Possible values:

  • CPC — ads
  • CPM — banners

UTM_CAMPAIGN
string

Designation of the advertising campaign

UTM_CONTENT
string

Content of the campaign. For example, for contextual ads

UTM_TERM
string

Search condition of the campaign. For example, keywords for contextual advertising

UF_CRM_...

Custom fields. For example, UF_CRM_25534736.

Depending on the portal settings, deals may have a set of custom fields of specific types.

Values of multiple fields are passed as an array.

To change file fields, it is recommended to use the method crm.item.update.

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

PARENT_ID_...
crm_entity

Relationship fields.

If there are smart processes related to deals on the portal, there is a field for each such smart process that stores the relationship between this smart process and the deal. The field itself stores the identifier of the element of that smart process.

For example, the field PARENT_ID_153 — relationship with the smart process entityTypeId=153, stores the identifier of the element of this smart process related to the current deal

Parameter params

Name
type

Description

REGISTER_SONET_EVENT
boolean

Whether to register the deal change event in the activity stream. Possible values:

  • Y — yes
  • N — no

REGISTER_HISTORY_EVENT
boolean

Whether to create a history record. Possible values:

  • Y — yes
  • N — no

Code Examples

How to Use Examples in Documentation

curl -X POST \
        -H "Content-Type: application/json" \
        -H "Accept: application/json" \
        -d '{"ID":123,"FIELDS":{"TITLE":"New Deal Title!","TYPE_ID":"GOODS","STAGE_ID":"WON","IS_RECURRING":"Y","IS_RETURN_CUSTOMER":"Y","OPPORTUNITY":9999.99,"IS_MANUAL_OPPORTUNITY":"Y","ASSIGNED_BY_ID":1,"UF_CRM_1725365197310":"String","PARENT_ID_1032":1},"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.deal.update
        
curl -X POST \
        -H "Content-Type: application/json" \
        -H "Accept: application/json" \
        -d '{"ID":123,"FIELDS":{"TITLE":"New Deal Title!","TYPE_ID":"GOODS","STAGE_ID":"WON","IS_RECURRING":"Y","IS_RETURN_CUSTOMER":"Y","OPPORTUNITY":9999.99,"IS_MANUAL_OPPORTUNITY":"Y","ASSIGNED_BY_ID":1,"UF_CRM_1725365197310":"String","PARENT_ID_1032":1},"PARAMS":{"REGISTER_SONET_EVENT":"N","REGISTER_HISTORY_EVENT":"N"},"auth":"**put_access_token_here**"}' \
        https://**put_your_bitrix24_address**/rest/crm.deal.update
        
try
        {
        	const response = await $b24.callMethod(
        		'crm.deal.update',
        		{
        			id: 123,
        			fields: {
        				TITLE: "New Deal Title!",
        				TYPE_ID: "GOODS",
        				STAGE_ID: "WON",
        				IS_RECURRING: "Y",
        				IS_RETURN_CUSTOMER: "Y",
        				OPPORTUNITY: 9999.99,
        				IS_MANUAL_OPPORTUNITY: "Y",
        				ASSIGNED_BY_ID: 1,
        				UF_CRM_1725365197310: "String",
        				PARENT_ID_1032: 1,
        			},
        			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 {
            $response = $b24Service
                ->core
                ->call(
                    'crm.deal.update',
                    [
                        'id' => 123,
                        'fields' => [
                            'TITLE'              => "New Deal Title!",
                            'TYPE_ID'            => "GOODS",
                            'STAGE_ID'           => "WON",
                            'IS_RECURRING'       => "Y",
                            'IS_RETURN_CUSTOMER' => "Y",
                            'OPPORTUNITY'        => 9999.99,
                            'IS_MANUAL_OPPORTUNITY' => "Y",
                            'ASSIGNED_BY_ID'     => 1,
                            'UF_CRM_1725365197310' => "String",
                            'PARENT_ID_1032'     => 1,
                        ],
                        'params' => [
                            'REGISTER_SONET_EVENT'   => "N",
                            'REGISTER_HISTORY_EVENT' => "N",
                        ],
                    ]
                );
        
            $result = $response
                ->getResponseData()
                ->getResult();
        
            if ($response->getError()) {
                echo 'Error: ' . $response->getError();
            } else {
                echo 'Success: ' . print_r($result, true);
                // Your logic for processing data
                processData($result);
            }
        
        } catch (Throwable $e) {
            error_log($e->getMessage());
            echo 'Error updating deal: ' . $e->getMessage();
        }
        
BX24.callMethod(
            'crm.deal.update',
            {
                id: 123,
                fields: {
                    TITLE: "New Deal Title!",
                    TYPE_ID: "GOODS",
                    STAGE_ID: "WON",
                    IS_RECURRING: "Y",
                    IS_RETURN_CUSTOMER: "Y",
                    OPPORTUNITY: 9999.99,
                    IS_MANUAL_OPPORTUNITY: "Y",
                    ASSIGNED_BY_ID: 1,
                    UF_CRM_1725365197310: "String",
                    PARENT_ID_1032: 1,
                },
                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.deal.update',
            [
                'ID' => 123,
                'FIELDS' => [
                    'TITLE' => 'New Deal Title!',
                    'TYPE_ID' => 'GOODS',
                    'STAGE_ID' => 'WON',
                    'IS_RECURRING' => 'Y',
                    'IS_RETURN_CUSTOMER' => 'Y',
                    'OPPORTUNITY' => 9999.99,
                    'IS_MANUAL_OPPORTUNITY' => 'Y',
                    'ASSIGNED_BY_ID' => 1,
                    'UF_CRM_1725365197310' => 'String',
                    'PARENT_ID_1032' => 1,
                ],
                'PARAMS' => [
                    'REGISTER_SONET_EVENT' => 'N',
                    'REGISTER_HISTORY_EVENT' => 'N',
                ],
            ]
        );
        
        echo '<PRE>';
        print_r($result);
        echo '</PRE>';
        

Method Explanation

For managing deal contacts, it is not recommended to use the fields CONTACT_IDS and CONTACT_ID.

Use the methods crm.deal.contact.* for working with a single contact, and the methods crm.deal.contact.items.* for working with a group of deal contacts.

Response Handling

HTTP status: 200

{
            "result": true,
            "time": {
                "start": 1725365418.056843,
                "finish": 1725365419.671506,
                "duration": 1.6146628856658936,
                "processing": 1.3475170135498047,
                "date_start": "2024-09-03T14:10:18+02:00",
                "date_finish": "2024-09-03T14:10:19+02:00",
                "operating": 0
            }
        }
        

Returned Data

Name
type

Description

result
boolean

Root element of the response, contains true in case of success

time
time

Information about the execution time of the request

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

-

ID is not defined or invalid

The parameter id is not a positive integer

-

Not found

The deal with the provided id does not exist

-

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 "edit" deals

-

Disk resource exhausted

-

Invalid value for the "Currency" field

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