To transfer stock balances to other systems — ERP, CMS, self-written websites, etc. — you can set up a webhook in keyCRM. The system will automatically send updated stock data every time it changes.
Adding a webhook
Go to «Settings» → «Products» → «Stocks» tab and click «+Add Webhook» in the «Webhooks» block.
Fill in the fields in the window:
-
Name — write a clear name, it is better to specify where the data from this webhook is sent;
-
Webhook URL — enter the URL of the webhook where the data will be sent using the POST method;
- Warehouses — select the warehouse from which the remaining items will be sent. If you select several, the total for all of them will be taken. If you leave it blank, the total for all warehouses will be taken.
Click «Add», and the webhook will be saved to the list with the option to edit or delete it.
To save the settings, click «Save» at the bottom of the page, and the data will start being sent to the added webhook:
How balance transfer to webhook works
Balances are sent when they change in keyCRM, namely after:
-
transferring an order to a status in which the product is reserved or written off from the warehouse, or canceling the reservation and write-off;
-
creating or editing documents: stocks receipt, transfer, inventory of products;
-
importing balances (you can use the initial balance upload);
-
changing balances via API;
-
editing balances manually.
After adding a new webhook, balances that are already saved in products will not be transferred. Only when the next changes are made to the specified list of events will the updated balance data be transferred.
Information sent upon balance changes in JSON format:
[
{
"offer_id": 130827, // product variant ID
"sku": "a001-56", // SKU
"in_stock": 16, // total product stock
"in_reserve": 3 // how much of the total stock is reserved
}
]
To determine the available balance of products for sale, taking into account the reserve, you can subtract the reserve "in_reserve" from the total balance "in_stock" when receiving data.