Transferring Balance Changes via Webhook

We explain how to set up a webhook to transfer changes in stock levels, what data is sent, and under what circumstances.
Written by Владислав Пономарь
Updated 13 hours ago

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.

Note! To enable the functionality of transferring balances to a webhook, first enable stock management.

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;

Note! For the webhook to work, a script handler must be configured at the link you specified to accept POST requests and process the received JSON. Implementing such a script requires the involvement of a developer on your side.
  • 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.
You can test the webhook and see what data you will receive using the webhook.site service.

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.

Tags: stock updates, inventory management, webhook, webhooks, stock changes, stock transfer, stock dispatch, new stock
Did this answer your question?