Receiving iVendNext webhooks safely — the recipe
This recipe is for an iVendNext Partner whose own server, in any language, must react when something happens in a retailer's iVendNext — a sale is booked, stock moves. The sample to copy is samples/s1_warranty/service/receiver.py (verify, replay) and service/app.py (idempotent handling, reconciliation).
Next: Build your first appAll recipes

A phone sold at the till; seconds later the sample's warranty service, told by a signed webhook, has put its comment on the sale in Desk.
⚠ Since 2026-10-04 a webhook is the NUDGE, not the record. To learn reliably what happened in a retailer's iVendNext, read the event feed (
recipes/event_feed.md): a queue you pull and mark done, so nothing is lost while you are down. Use a webhook only to be told to pull now (event_feed.mdappendix A). This recipe stays for verifying a signed webhook — the nudge's signature is checked exactly as below.
When to use it: your server receives webhooks from a retailer's iVendNext, as a nudge to pull the event feed or on their own.
A webhook is a doorbell, not a parcel. Treat the call as "this sale changed", read the sale yourself over the API, and make every step safe to repeat. The five rules below follow from how iVendNext sends webhooks today.
1. Subscribe with a secret, and keep the payload thin
A retailer's administrator (it needs the System Manager role) creates a Webhook for the record type and event. For a booked sale, that is Sales Invoice and POS Invoice on Submit, with:
- Enable Security on, and a long random Webhook Secret that only you and iVendNext know;
- Request Structure: JSON, with a body that names the record and when it changed, and nothing more:
{"doctype": "{{ doc.doctype }}", "name": "{{ doc.name }}", "event": "on_submit",
"modified": "{{ doc.modified }}", "company": "{{ doc.company }}"}
A thin body keeps the signature check simple (rule 2) and keeps customer data out of request logs. Everything else you read over the API, with your integration user's own permissions.
2. Verify the signature — over the raw body
Each call carries X-Frappe-Webhook-Signature: the base64 of HMAC-SHA256(secret, body). Compute it over the exact bytes you received, and compare in constant time:
expected = base64.b64encode(hmac.new(secret.encode(), raw_body, hashlib.sha256).digest())
ok = hmac.compare_digest(expected, request.headers["X-Frappe-Webhook-Signature"].encode())
Refuse anything else with 401: a missing header, a wrong signature, a body changed after signing. Check the signature before parsing anything.
⚠ Read the raw body whatever Content-Type says. iVendNext sets no Content-Type itself. Desk's Webhook form adds application/json when Request Structure is JSON; a subscription made another way may carry none.
⚠ Never rebuild the body before you verify it. How the JSON is laid out is the sender's choice, and it differs between iVendNext releases: one sends it on one line, another indented with its keys sorted. A receiver that parses the body and serialises it again will refuse every call from a release that lays it out differently; one that verifies the bytes it received works on all of them.
⚠ Keep the body to plain JSON values, which is what rule 1's template produces. On the release that sends the JSON on one line, a custom body that holds a non-JSON value (a date object, a decimal) is not sent at all: signing it fails, and the retailer's iVendNext only logs the failure.
3. Reject replays
Nothing time-bound is signed, so a captured call stays valid for ever. Keep a seen-set keyed on record type + name + event + modified. Answer a key you have already handled with 200, and do nothing. Record the key only after you have handled the call; then a delivery that failed half-way is handled again on its retry.
4. Make the handling idempotent
The same sale can reach you more than once: a retry, a replay that slips past a lost seen-set, and the reconciliation pull (rule 5). So:
- keep your own record of the sales you have handled, and skip a handled one;
- before writing anything back into the retailer's iVendNext (a Comment, say), check over the API whether your earlier write is already there. That way a crash between "wrote it" and "recorded it" can never write it twice;
- make your own writes keyed and unique (e.g. one warranty per serial number).
Answer within the webhook's timeout (our tests used 10 seconds). Slow work goes to your own queue. Answer 200 once the call is verified and recorded.
5. When your service is down — recover what never arrived with the reconciliation pull
iVendNext tries a delivery three times within one background job (a few seconds apart), writes a Webhook Request Log row per attempt, and then stops. There is no later retry. If your server is down for those few seconds, the event is lost. So run this pull on a schedule (nightly is enough for most partners) and after every restart of your service:
GET /api/resource/Sales Invoice (and the same for POS Invoice, if you subscribe to till sales)
?fields=["name","modified"]
&filters=[["docstatus","=",1],["modified",">=","<your watermark>"]]
&order_by=modified asc&limit_page_length=200
Handle each sale idempotently (rule 4), then move your watermark to the newest modified you handled. Use >=, not >: two sales can share a timestamp, and rule 4 makes the overlap harmless. If one sale fails, stop there, so the watermark stays before it and the next pass retries it.
What we would like to improve
Proposed to our product team: a signed timestamp (so a receiver can reject old calls without a seen-set), delivery that survives a receiver being down for longer than a few seconds, and self-service subscriptions that need no System Manager. Until then, rules 3 and 5 are not optional.
Technical notes
- The sample.
samples/s1_warranty/service/receiver.pyandservice/app.pyare proven end to end on our test bench. The GIF is the sample's own walk (seesamples/s1_warranty/README.mdfor its date, frames and pin). - Rule 2, the header and the layout. On 2026-11-12 one signed webhook was captured on a test build of the current release and one on the release after it: on both the header is the base64 HMAC-SHA256 of the bytes sent. The sending code and Desk's Webhook form were re-read on both on 2026-11-13. Newer builds also send the same value as
X-iVendNext-Webhook-Signature; the release retailers run today does not yet, so read the header above until every release in service sends both. - Rule 2, plain JSON values. ⚠ Measured on our test bench, on the release that sends the JSON on one line. That release serialises the body twice, once to sign and once to send; the two were byte-identical for rule 1's template, and our tests checked this on a real sale's delivery.