Закажите бесплатную презентацию продуктов РосБизнесСофт прямо сейчас!
Webhooks используются для получения уведомлений в сторонних приложениях (сервисах) при изменении (добавление, редактирование, удаление) «Объектов» в Системе.
Формат отправляемых данных:
При аренде Системы модуль «Webhooks» активен по умолчанию.
В «коробочной» поставке активация модуля «Webhooks» происходит в файле «config.php»: webhooks_enable=1.
Все настройки Webhooks производятся в раздели меню «Настройки» — «Webhooks».
Настройка Webhooks доступна только для пользователя с правами «Администратор».

Можно использовать, как сгруппированный список, так и одиночный. Это реализовано для удобства отображения и изменений.
В каждой группе может быть один из типов отправляемых данных: JSON или XML.
Каждый Webhook можно привязать к следующим событиям:
Обращаем внимание, что Webhook вызывается только при работе с «Объектом» через формы (интерфейс Системы), а не через ORM.

Где:
JSON($_POST["json"]) или XML($_POST["xml"])
Произошло событие: Сохранили документ «Счет» с id=17
Пример PHP-кода:
<?php
if(isset($_POST['json'])){
$result = json_decode($_POST['json'],true);
//Получить имя
if(isset($result['request']) &&
isset($result['request']['action']) &&
isset($result['request']['action']['structure'])){
$jsonStructure = $result['request']['action']['structure'];
if($jsonStructure){
echo $jsonStructure['name'];
}
}
}
?>Результат:
"request": {
"action": {
"type": "edit",
"structure": {
"name": "documents.orders",
"key": 17,
"fields": {
"date": "07.09.2018 17:21",
"id": "17",
"visible": "1",
"owner": "1",
"total": "0",
"company_details": "33",
"organization": "1",
"contact": "0",
"contract": "0",
"responsible": "18",
"storehouse": "2",
"phone": "",
"products": [
{
"structure": {
"name": "documents.orders.products",
"key": 28,
"fields": {
"name": "Product 1",
"id": "28",
"visible": "1",
"owner": "17",
"product": "15",
"price_nds": "0",
"nds": "0",
"nds_procent": "1",
"number": "1",
"total": "0",
"discount_conditions": "",
"reserve": "0",
"article": "",
"profit": "0"
}
}
},
{
"structure": {
"name": "documents.orders.products",
"key": 29,
"fields": {
"name": "Product 2",
"id": "29",
"visible": "1",
"owner": "17",
"product": "15",
"price_nds": "0",
"nds": "0",
"nds_procent": "1",
"number": "1",
"total": "0",
"discount_conditions": "",
"reserve": "0",
"article": "",
"profit": "0"
}
}
}
],
"stamp": "",
"noncash": "",
"comment": "",
"price_type": "11",
"email": "",
"profit": "0",
"id_1c": "0",
"payment_orders": "0",
"number": "12",
"new_1c": "1",
"order_payment_status": "1",
"branch": "0",
"position": "",
"limit": "0",
"order_comment": "",
"discount": "0",
"order": "",
"discount_text": "",
"payment_sum": "0",
"invoice_sum": "666",
"payment_percent": "0",
"task": "0",
"deal": "0",
"commercial": "0",
"phone_mobile": "",
"nds": "0",
"repair": "2",
"equipment": "0"
}
}
}
}Произошло событие: Сохранили документ «Счет» с id=17
Пример PHP-кода:
<?php
if(isset($_POST['xml'])){
libxml_use_internal_errors(true);
$request = simplexml_load_string($_POST['xml']);
while ($error = libxml_get_errors()) {
throw new \ErrorException("XML parsing error: " . $error[0]->message . " on line " . $error[0]->line);
}
if(!isset($request->action)){
throw new \ErrorException("XML parsing error: not action node ");
}
// "edit"
//echo $request->action->attributes()->type;
if(!isset($request->action->structure)){
throw new \ErrorException("empty Structure");
}
$structure = $request->action->structure;
if(!isset($structure->fields)){
throw new \ErrorException("structure ".$structure->attributes()->name." not found fields");
}
// echo (string)$structure->attributes()->name;
// "documents.orders"
foreach($structure->fields->children() as $field){
//this data field
//$field->getName() - field Name
//(string)$field->attributes()->type
}
}
?>Результат:
<request>
<action type="edit">
<structure name="documents.orders" key="17">
<fields>
<date type="date">07.09.2018 17:21</date>
<id type="numeric">17</id>
<visible type="bool">1</visible>
<owner type="delayed">1</owner>
<total type="numeric">0</total>
<company_details type="delayed">33</company_details>
<organization type="delayed">1</organization>
<contact type="delayed">0</contact>
<contract type="delayed">0</contract>
<responsible type="delayed">18</responsible>
<storehouse type="delayed">2</storehouse>
<phone type="varchar"></phone>
<products type="set">
<structure name="documents.orders.products" key="28">
<fields>
<name type="varchar">Product 1</name>
<id type="numeric">28</id>
<visible type="bool">1</visible>
<owner type="delayed">17</owner>
<product type="delayed">15</product>
<price_nds type="numeric">0</price_nds>
<nds type="numeric">0</nds>
<nds_procent type="delayed">1</nds_procent>
<number type="numeric">1</number>
<total type="numeric">0</total>
<discount_conditions type="varchar"></discount_conditions>
<reserve type="numeric">0</reserve>
<article type="varchar"></article>
<profit type="numeric">0</profit>
</fields>
</structure>
<structure name="documents.orders.products" key="29">
<fields>
<name type="varchar">Product 2</name>
<id type="numeric">29</id>
<visible type="bool">1</visible>
<owner type="delayed">17</owner>
<product type="delayed">15</product>
<price_nds type="numeric">0</price_nds>
<nds type="numeric">0</nds>
<nds_procent type="delayed">1</nds_procent>
<number type="numeric">1</number>
<total type="numeric">0</total>
<discount_conditions type="varchar"></discount_conditions>
<reserve type="numeric">0</reserve>
<article type="varchar"></article>
<profit type="numeric">0</profit>
</fields>
</structure>
</products>
<stamp type="bool"></stamp>
<noncash type="bool"></noncash>
<comment type="varchar"></comment>
<price_type type="delayed">11</price_type>
<email type="varchar"></email>
<profit type="numeric">0</profit>
<id_1c type="numeric">0</id_1c>
<payment_orders type="delayed">0</payment_orders>
<number type="numeric">12</number>
<new_1c type="bool">1</new_1c>
<order_payment_status type="delayed">1</order_payment_status>
<branch type="delayed">0</branch>
<position type="varchar"></position>
<limit type="numeric">0</limit>
<order_comment type="varchar"></order_comment>
<discount type="delayed">0</discount>
<order type="varchar"></order>
<discount_text type="varchar"></discount_text>
<payment_sum type="numeric">0</payment_sum>
<invoice_sum type="numeric">666</invoice_sum>
<payment_percent type="numeric">0</payment_percent>
<task type="delayed">0</task>
<deal type="delayed">0</deal>
<commercial type="delayed">0</commercial>
<phone_mobile type="varchar"></phone_mobile>
<nds type="numeric">0</nds>
<repair type="delayed">2</repair>
<equipment type="delayed">0</equipment>
</fields>
</structure>
</action>
</request>Используется, если необходимо вызвать цепочку Webhooks.
Например, если не через «Форму» удалили объект (visible=0), а явно через ORM, то можно вызвать:
Webhooks::runEvent();
Для использования класса, необходимо подключить:
use Kernel\Actions\WebHooks\Webhooks
getGroupedList()
Учитывает группу и возвращает многомерный массив. [ group_id => [] ]
getListByGroupId($group_id)
runEvent($entry, $action)
Где:
Запустить все webhooks для «References.contacts» событие «Edit»:
//$entry - object(references.contacts:1) Webhooks::runEvent($entry, "edit");