crm.orderentity.add
Добавить привязку заказа к объекту CRM
Описание
Метод добавляет привязку заказа к объекту CRM.
Параметры
fields
object
обязательный
Значения полей для создания привязки
Параметр fields
orderId
sale_order.id
обязательный
Идентификатор заказа
ownerTypeId
integer
обязательный
Идентификатор типа объекта CRM.
Привязка возможна только к сделке или счету
ownerId
integer
обязательный
Идентификатор объекта CRM.
Для сделок может быть получен методом crm.deal.list.
Для счетов может быть получен методом crm.invoice.list
Примеры запроса
curl -X POST \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d '{"fields":{"orderId":5125,"ownerId":6933,"ownerTypeId":2}}' \
https://**put_your_bitrix24_address**/rest/**put_your_user_id_here**/**put_your_webhook_here**/crm.orderentity.add
curl -X POST \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d '{"fields":{"orderId":5125,"ownerId":6933,"ownerTypeId":2},"auth":"**put_access_token_here**"}' \
https://**put_your_bitrix24_address**/rest/crm.orderentity.add
// This snippet is an ES module: top-level await requires type="module" or a bundler.
// $b24 is an already-initialized SDK instance (see the SDK "Get started" guide).
import { Text } from '@bitrix24/b24jssdk'
import type { B24Frame } from '@bitrix24/b24jssdk'
declare const $b24: B24Frame
// Shape of the payload returned in result (match the "response handling" section of the page)
type OrderEntityAddResult = {
dealOrder: {
orderId: number
ownerId: number
ownerTypeId: number
}
}
try {
const response = await $b24.actions.v2.call.make<OrderEntityAddResult>({
method: 'crm.orderentity.add',
params: {
fields: {
orderId: 5125,
ownerId: 6933,
ownerTypeId: 2,
},
},
requestId: Text.getUuidRfc4122()
})
// The payload is available only on a successful response
if (!response.isSuccess) {
console.error(response.getErrorMessages().join('; '))
} else {
const result = response.getData()!.result
console.info(result.dealOrder)
}
} catch (error) {
// Thrown on transport or SDK failures (AjaxError, SdkError, etc.)
console.error(error)
}
<!-- Load the SDK (UMD build); it is exposed as the global B24Js -->
<script src="https://unpkg.com/@bitrix24/b24jssdk@1/dist/umd/index.min.js"></script>
<script>
async function addOrderEntity() {
try {
// Initialize the SDK inside a Bitrix24 frame
const $b24 = await B24Js.initializeB24Frame()
const response = await $b24.actions.v2.call.make({
method: 'crm.orderentity.add',
params: {
fields: {
orderId: 5125,
ownerId: 6933,
ownerTypeId: 2,
},
},
requestId: B24Js.Text.getUuidRfc4122()
})
// The payload is available only on a successful response
if (!response.isSuccess) {
console.error(response.getErrorMessages().join('; '))
return
}
const result = response.getData().result
console.info(result.dealOrder)
} catch (error) {
// Thrown on transport or SDK failures (AjaxError, SdkError, etc.)
console.error(error)
}
}
document.addEventListener('DOMContentLoaded', addOrderEntity)
</script>
from b24pysdk.errors import BitrixAPIError, BitrixSDKException
try:
bitrix_response = client.crm.orderentity.add(
fields={
"orderId": 123,
"ownerTypeId": 2,
"ownerId": 15,
},
).response
result = bitrix_response.result
print(result)
except BitrixAPIError as error:
print(
"Ошибка Bitrix API",
f"error: {error.error}",
f"error_description: {error.error_description}",
sep="\n",
)
except BitrixSDKException as error:
print(f"Ошибка Bitrix SDK: {error.message}")
except Exception as error:
print(f"Непредвиденная ошибка: {error}")
BX24.callMethod(
"crm.orderentity.add",
{
fields: {
orderId: 5125,
ownerId: 6933,
ownerTypeId: 2
}
},
)
.then(
function(result)
{
if (result.error())
{
console.error(result.error());
}
else
{
console.log(result);
}
},
function(error)
{
console.info(error);
}
);
require_once('crest.php');
$result = CRest::call(
'crm.orderentity.add',
[
'fields' => [
'orderId' => 5125,
'ownerId' => 6933,
'ownerTypeId' => 2
]
]
);
echo '<PRE>';
print_r($result);
echo '</PRE>';
// client и ctx уже созданы — см. раздел «SDK для Go»
res, err := client.Core().Call(ctx, "crm.orderentity.add", b24.Params{
"fields": b24.Params{
"orderId": 5125,
"ownerId": 6933,
"ownerTypeId": 2,
},
})
if err != nil {
return fmt.Errorf("crm.orderentity.add: %w", err)
}
// Метод заворачивает ответ в объект с ключом "dealOrder".
raw, ok := b24.Unwrap(res.Result, "dealOrder")
if !ok {
return fmt.Errorf("в ответе нет ключа dealOrder")
}
var item struct {
OrderID b24.ID `json:"orderId"`
OwnerID b24.ID `json:"ownerId"`
OwnerTypeID b24.ID `json:"ownerTypeId"`
}
if err := json.Unmarshal(raw, &item); err != nil {
return fmt.Errorf("разбор ответа: %w", err)
}
fmt.Println(item.OrderID, item.OwnerID)
Ответ
HTTP-статус: 200
{
"result": {
"dealOrder": {
"orderId": 5125,
"ownerId": 6933,
"ownerTypeId": 2
}
},
"time": {
"start": 1719325851.568441,
"finish": 1719325852.546479,
"duration": 0.9780380725860596,
"processing": 0.32780981063842773,
"date_start": "2024-06-25T16:30:51+02:00",
"date_finish": "2024-06-25T16:30:52+02:00",
"operating": 0
}
}
Возвращаемые данные
result
object
Корневой элемент ответа
dealOrder
crm_orderentity
Объект с информацией о созданной привязке
time
time
Информация о времени выполнения запроса
Обработка ошибок
HTTP-статус: 400
{
"error": "201650000001",
"error_description": "Duplicate entry for key [ownerId, ownerTypeId, orderId]"
}

