This document outlines how to configure and handle multiple webhooks for Smart Processes in Bitrix24. Each webhook will perform different actions based on the event triggered from Bitrix24 CRM.
- Bitrix24 is required for these webhooks to work.
- You need to set up webhook URLs for each event you want to capture and process.
Smart Processes in Bitrix24 allow automation of business workflows by connecting various elements, such as invoices, contracts, and products, into a streamlined process. These processes can be used to simplify complex CRM tasks, automatically updating data and ensuring that different systems and people stay in sync.
Webhooks are used to trigger external actions or update external systems when certain events happen within a Smart Process. The main purpose of these webhooks is to automate repetitive tasks and update data across systems.
This webhook is triggered when there are changes to smart invoices or dynamic items. When items in a smart invoice are added or updated, the webhook creates or updates a corresponding smart process helper. This helper is responsible for calculating the total amount of the entire invoice, simplifying the management of data and ensuring the process remains accurate.
The webhook automates the process of handling invoice data, ensuring that any changes to the smart invoice are reflected in the workflow without requiring manual intervention. This not only saves time but also helps keep the system synchronized, improving overall efficiency in managing invoice-related tasks.
-
ONCRMDYNAMICITEMUPDATE:
- When a dynamic item is updated in a smart invoice, it retrieves the invoice products, processes them, and updates the corresponding smart process element.
-
ONCRMDYNAMICITEMADD:
- When a new dynamic item is added to the smart invoice, it processes the products and adds a new smart process element.
This webhook is triggered when a deal is created, updated, or deleted. When a new deal is created or updated, it automatically adds or updates the products associated with the deal in a universal list. This list is used for managing items for shipment. The webhook ensures that the relevant products are synced with the list, making the process of handling product shipments more efficient.
When a deal is updated, the webhook ensures that the products in the deal are synchronized with the list, adding, updating, or removing products as necessary. If a deal is deleted, the associated products are removed from the list.
This process simplifies the management of products for shipment, ensuring that the system stays synchronized and up-to-date with the latest changes in the deals.
-
ONCRMDEALADD:
- When a new deal is created, it fetches the associated products using the
getDealProductsfunction and adds them to a list using theaddToListBatchfunction.
- When a new deal is created, it fetches the associated products using the
-
ONCRMDEALUPDATE:
- When a deal is updated, it syncs the products of the deal with the list using the
syncDealProductsWithListfunction.
- When a deal is updated, it syncs the products of the deal with the list using the
-
ONCRMDEALDELETE:
- When a deal is deleted, it removes the associated elements from the list using the
deleteFromListBatchfunction.
- When a deal is deleted, it removes the associated elements from the list using the
- Both scripts use Bitrix's
CRest::callandCRest::callBatchmethods to interact with Bitrix's REST API. - The products are retrieved and processed, and various actions (add, update, delete) are performed based on the event type.
- Logging is performed to capture the incoming data and batch requests, which can be useful for debugging and auditing.
Before running the webhooks, you may need to configure the CRest class with the following options to customize its behavior. These options control things like SSL validation, encoding settings, and logging preferences.
// Webhook URL. Make sure you configured required permissions for webhook
define('C_REST_WEB_HOOK_URL', 'https://bitrix24.com/rest/your-url-here/');
// Optional configuration options:
// Define encoding if needed (for example, when working with non-UTF-8 characters)
define('C_REST_CURRENT_ENCODING', 'windows-1251');
// Turn off SSL validation for testing or development purposes (not recommended for production)
define('C_REST_IGNORE_SSL', true);
// Enable detailed logging for debugging, helpful in capturing full requests and responses
define('C_REST_LOG_TYPE_DUMP', true);
// Disable default logging if preferred, using a custom logging mechanism
define('C_REST_BLOCK_LOG', true);
// Directory to store log files for future reference
define('C_REST_LOGS_DIR', __DIR__ . '/logs/');Interested in building your custom solution with Bitrix24? Contact our team for a consultation and let’s create something exceptional together!