Set Products in Deal crm.deal.productrows.set

Scope: crm

Who can execute the method: user with "modify" access permission for the deal

Method Development Halted

The method crm.deal.productrows.set is still operational, but there is a more current equivalent: crm.item.productrow.*.

The method crm.deal.productrows.set creates or updates the product rows of a deal. Existing rows that are not passed to the method will be removed from the deal.

To modify only a single row, use the methods crm.item.productrow.*.

Name
type

Description

id*
integer

Identifier of the deal. Can be obtained using the method to retrieve the list of deals: crm.deal.list or when creating a deal: crm.deal.add

rows
object[]

Product rows

An array of objects in the following format:

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

where

  • field_n — name of the product row field
  • value_n — value of this field

The list of available fields is described below

List of Available Fields for Product Rows

Name
type

Description

PRODUCT_ID
integer

Identifier of the product in the catalog. The list of products can be obtained using the method catalog.product.list
0 if not from the catalog

Default - 0

PRODUCT_NAME
string

Name of the product row. If PRODUCT_ID is provided, the name will be taken from the product

If both PRODUCT_ID and PRODUCT_NAME are not provided, then PRODUCT_NAME will equal [{id}], where {id} is the identifier of the created product row

PRICE
double

Final cost of the product per unit

Default - 0.0

PRICE_EXCLUSIVE
double

Cost per unit considering discounts, excluding taxes

PRICE_NETTO
double

Cost per unit excluding discounts and taxes

PRICE_BRUTTO
double

Cost per unit excluding discounts but including taxes

QUANTITY
double

Quantity of product units

Default - 1.0

DISCOUNT_TYPE_ID
integer

Type of discount
Possible types:

  • 1 - Absolute
  • 2 - Percentage

Default - 2

DISCOUNT_RATE
double

Discount value in percentage (if percentage discount type is used)

Default - 0.0

DISCOUNT_SUM
double

Absolute discount value (if absolute discount type is used)

Default - 0.0

TAX_RATE
double

Tax rate in percentage

TAX_INCLUDED
char

Indicator of whether tax is included in the price
Possible values:

  • Y – tax included
  • N – tax not included

Default - N

MEASURE_CODE
catalog_measure.code

Unit of measure code

If PRODUCT_ID is provided, the default value will be taken from the product, otherwise 0

MEASURE_NAME
string

Text representation of the unit of measure (e.g., pcs, kg, m, l, etc.)

If PRODUCT_ID is provided, the default value will be taken from the product, otherwise ""

SORT
integer

Sorting

Default - 0

Code Examples

How to Use Examples in Documentation

curl -X POST \
        -H "Content-Type: application/json" \
        -H "Accept: application/json" \
        -d '{"id":5,"rows":[{"PRODUCT_ID":456,"PRICE":1000,"QUANTITY":10,"DISCOUNT_TYPE_ID":1,"DISCOUNT_SUM":100,"TAX_RATE":13,"MEASURE_CODE":796,"MEASURE_NAME":"pcs","SORT":10},{"PRODUCT_NAME":"Product #2","PRICE":500,"QUANTITY":5,"DISCOUNT_TYPE_ID":2,"DISCOUNT_RATE":10,"TAX_RATE":10,"MEASURE_CODE":166,"MEASURE_NAME":"kg","SORT":20}]}' \
        https://**put_your_bitrix24_address**/rest/**put_your_user_id_here**/**put_your_webhook_here**/crm.deal.productrows.set
        
curl -X POST \
        -H "Content-Type: application/json" \
        -H "Accept: application/json" \
        -d '{"id":5,"rows":[{"PRODUCT_ID":456,"PRICE":1000,"QUANTITY":10,"DISCOUNT_TYPE_ID":1,"DISCOUNT_SUM":100,"TAX_RATE":13,"MEASURE_CODE":796,"MEASURE_NAME":"pcs","SORT":10},{"PRODUCT_NAME":"Product #2","PRICE":500,"QUANTITY":5,"DISCOUNT_TYPE_ID":2,"DISCOUNT_RATE":10,"TAX_RATE":10,"MEASURE_CODE":166,"MEASURE_NAME":"kg","SORT":20}],"auth":"**put_access_token_here**"}' \
        https://**put_your_bitrix24_address**/rest/crm.deal.productrows.set
        
try
        {
        	const response = await $b24.callMethod(
        		'crm.deal.productrows.set',
        		{
        			id: 5,
        			rows: [
        				{
        					PRODUCT_ID: 456,
        					PRICE: 1000,
        					QUANTITY: 10,
        					DISCOUNT_TYPE_ID: 1,
        					DISCOUNT_SUM: 100,
        					TAX_RATE: 13,
        					MEASURE_CODE: 796,
        					MEASURE_NAME: "pcs",
        					SORT: 10,
        				},
        				{
        					PRODUCT_NAME: "Product #2",
        					PRICE: 500,
        					QUANTITY: 5,
        					DISCOUNT_TYPE_ID: 2,
        					DISCOUNT_RATE: 10,
        					TAX_RATE: 10,
        					MEASURE_CODE: 166,
        					MEASURE_NAME: "kg",
        					SORT: 20,
        				},
        			],
        		}
        	);
        	
        	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.productrows.set',
                    [
                        'id'   => 5,
                        'rows' => [
                            [
                                'PRODUCT_ID'       => 456,
                                'PRICE'           => 1000,
                                'QUANTITY'        => 10,
                                'DISCOUNT_TYPE_ID' => 1,
                                'DISCOUNT_SUM'    => 100,
                                'TAX_RATE'        => 13,
                                'MEASURE_CODE'    => 796,
                                'MEASURE_NAME'    => "pcs",
                                'SORT'            => 10,
                            ],
                            [
                                'PRODUCT_NAME'     => "Product #2",
                                'PRICE'           => 500,
                                'QUANTITY'        => 5,
                                'DISCOUNT_TYPE_ID' => 2,
                                'DISCOUNT_RATE'   => 10,
                                'TAX_RATE'        => 10,
                                'MEASURE_CODE'    => 166,
                                'MEASURE_NAME'    => "kg",
                                'SORT'            => 20,
                            ],
                        ],
                    ]
                );
        
            $result = $response
                ->getResponseData()
                ->getResult();
        
            if ($result->error()) {
                error_log($result->error());
                echo 'Error: ' . $result->error();
            } else {
                echo 'Success: ' . print_r($result->data(), true);
            }
        
        } catch (Throwable $e) {
            error_log($e->getMessage());
            echo 'Error setting deal product rows: ' . $e->getMessage();
        }
        
BX24.callMethod(
            'crm.deal.productrows.set',
            {
                id: 5,
                rows: [
                    {
                        PRODUCT_ID: 456,
                        PRICE: 1000,
                        QUANTITY: 10,
                        DISCOUNT_TYPE_ID: 1,
                        DISCOUNT_SUM: 100,
                        TAX_RATE: 13,
                        MEASURE_CODE: 796,
                        MEASURE_NAME: "pcs",
                        SORT: 10,
                    },
                    {
                        PRODUCT_NAME: "Product #2",
                        PRICE: 500,
                        QUANTITY: 5,
                        DISCOUNT_TYPE_ID: 2,
                        DISCOUNT_RATE: 10,
                        TAX_RATE: 10,
                        MEASURE_CODE: 166,
                        MEASURE_NAME: "kg",
                        SORT: 20,
                    },
                ],
            },
            (result) => {
                result.error()
                    ? console.error(result.error())
                    : console.info(result.data())
                ;
            },
        );
        
require_once('crest.php');
        
        $result = CRest::call(
            'crm.deal.productrows.set',
            [
                'id' => 5,
                'rows' => [
                    [
                        'PRODUCT_ID' => 456,
                        'PRICE' => 1000,
                        'QUANTITY' => 10,
                        'DISCOUNT_TYPE_ID' => 1,
                        'DISCOUNT_SUM' => 100,
                        'TAX_RATE' => 13,
                        'MEASURE_CODE' => 796,
                        'MEASURE_NAME' => "pcs",
                        'SORT' => 10,
                    ],
                    [
                        'PRODUCT_NAME' => "Product #2",
                        'PRICE' => 500,
                        'QUANTITY' => 5,
                        'DISCOUNT_TYPE_ID' => 2,
                        'DISCOUNT_RATE' => 10,
                        'TAX_RATE' => 10,
                        'MEASURE_CODE' => 166,
                        'MEASURE_NAME' => "kg",
                        'SORT' => 20,
                    ],
                ]
            ]
        );
        
        echo '<PRE>';
        print_r($result);
        echo '</PRE>';
        

Response Handling

HTTP Status: 200

{
          "result": true,
          "time": {
            "start": 1735134795.171273,
            "finish": 1735134796.404978,
            "duration": 1.2337050437927246,
            "processing": 0.9462978839874268,
            "date_start": "2024-12-25T15:53:15+02:00",
            "date_finish": "2024-12-25T15:53:16+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_CORE",
          "error_description": "Discount Sum (DISCOUNT_SUM) is required if Percentage Discount Type (DISCOUNT_TYPE_ID) is defined and Discount Rate (DISCOUNT_RATE) is 100%<br>"
        }
        

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

Description

Value

The parameter id is invalid or not defined

An incorrect value was passed to the id parameter

Access denied

The user does not have permission to "modify" the deal

Not found

The deal with the provided id was not found

Discount Rate (DISCOUNT_RATE) is required if Percentage Discount Type (DISCOUNT_TYPE_ID) is defined

DISCOUNT_TYPE_ID = 2 was passed without DISCOUNT_RATE

Discount Sum (DISCOUNT_SUM) is required if Percentage Discount Type (DISCOUNT_TYPE_ID) is defined and Discount Rate (DISCOUNT_RATE) is 100%

DISCOUNT_RATE = 100 and DISCOUNT_TYPE_ID = 2 were passed without DISCOUNT_SUM

Discount Sum (DISCOUNT_SUM) is required if Monetary Discount Type (DISCOUNT_TYPE_ID) is defined

DISCOUNT_TYPE_ID = 1 was passed without DISCOUNT_SUM

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