Commerce Webhooks
A webhook is a message that Commerce sends to a web address you own, the moment something happens: a customer registers, signs in, or a campaign changes. Instead of asking Commerce for changes on a schedule, you publish one address and Commerce calls it.
Setting one up takes three steps, and this page walks through each of them:
Subscribe to the event you care about, giving Commerce the address to call.
Receive the message on that address, check that it really came from Akinon, and answer quickly.
Confirm afterwards, from your own logs and from the delivery records Akinon keeps.
Every webhook is an HTTP POST whose body always has the same two parts: an event object saying what happened, and a payload object carrying the record it happened to:
{
"event": {"type": "user_registered", "uuid": "c9591f0d1c1d4da58ade880921bd7e93"},
"payload": { "...": "..." }
}Before you start you will need an API token, and an address that accepts POST requests from the public internet.
dj-whisperer
The dj-whisperer package, developed within Akinon, has been released as an open-source project and is available on PyPI:
PyPI Package: dj-whisperer
Documentation: dj-whisperer Docs
Through dj-whisperer, you can subscribe to various webhook events in the Commerce system. The official package documentation provides in-depth details on how to configure and utilize webhooks efficiently.
Subscribing to an Event
A subscription is made of two pieces, and it is worth knowing what each one decides:
An event message definition turns the event on and chooses how it is delivered. Nothing is sent for an event that has no definition.
A hook describes one destination for queued delivery: where the message goes, how it is signed, which headers it carries, and how long to wait between retries.
Immediate delivery needs only a definition, which carries the address itself. Queued delivery needs both: the definition to turn the event on, and a hook to say where it goes.
Whether the event is sent at all
The definition
The definition
Where the message goes
The definition's url
Each active hook's target_url
How the request proves itself
The definition's authentication_config
The hook's secret_key signature and additional_headers
Retries
None
The hook's retry_countdown_config
Delivery records you can read later
Not kept
Kept, in hook_events
Both pieces can exist more than once for the same event, and each one is handled on its own: every definition for an event is acted on when it fires, and in queued mode every active hook for that event name receives its own copy with its own delivery record. That is how you feed two systems from one event. It is also why a duplicate definition or a forgotten hook means the same event arriving twice.
Start with the definition. The event names are listed in Available Commerce Webhook Events at the end of this page.
Parameters:
event_name: One of the predefined Commerce event names.description: A free-text note describing what this definition is for.url: The address the event will be sent to.authentication_config: Credentials for that address, if it requires them. Basic authentication is supported.asynchronous: Chooses the delivery mode (see below).transactional: Only applies in immediate mode (see below).
Choosing a delivery mode
Immediate (asynchronous: false) sends the message during the operation that caused it, while the change is still being written. It is the fastest possible notice, and it is the right choice when all you need is the trigger.
Three things follow from sending it that early:
The payload shows the record as it stands at that instant. Anything written a moment later in the same operation, such as related records and lists that are filled in afterwards, is not in it yet.
The message is sent once. The delivery is judged on whether the request reached your address at all; the answer your endpoint gives back is not examined, and nothing is re-sent.
The message is not signed. An immediate message carries no
X-Whisperer-Signatureheader, because the signature belongs to the hook and an immediate message is sent without one. Authenticate that address with theauthentication_configcredentials instead, and do not expect a signature to verify.
With transactional: true, an address that cannot be reached at all (a wrong host, a refused connection, no answer in time) cancels the operation that caused the event. A customer registration would fail, for example. Use it only when that is genuinely what you want.
Queued (asynchronous: true) hands the message to a background queue instead. It goes out once the change has been stored completely, so the payload is whole, and it is retried if your endpoint is unavailable. This is the right default for most integrations.
Queued delivery takes its destination from the hook rather than from the definition's url, so register a hook for the same event name alongside the definition:
event_type: The same event name as in the definition.target_url: The address the event will be sent to.secret_key: A random string that you choose and keep private. Akinon does not issue it and never sends it in a request; it is stored on the hook and used to sign every message, so you can prove the request came from Akinon. Optional, but strongly recommended. See Confirming a Delivery.retry_countdown_config: How long to wait between retries. See Setting the retry interval.additional_headers: Any extra headers your address needs, such as an authorization token.config: Optional. Add{"auth": {"auth_type": "basic", "username": "…", "password": "…"}}when your address expects a username and password rather than a header.
A successful registration answers 201 with the stored hook, including the id you will need to change it later. Two answers mean the hook was not created:
400with"… is not a valid choice.": theevent_typeis not a Commerce event name. The API can list the valid ones for you:
406withwebhook_100_2: you already have a hook for this event name and this address. One address can be registered once per event; use the existing hook, or point the new one somewhere else.
Managing your hooks
Set is_active back to true to resume. Both pausing and deleting stop new deliveries, but a message that was already queued, or that is waiting for its next retry, can still go out after you make the change.
A deleted hook keeps its registration: it stays in the list as inactive, and registering the same event name and address again answers 406. To use that address again, set is_active back to true on the existing hook.
You only ever see and change your own hooks; a token cannot read another integration's.
When an Event Is Triggered
Immediate
During the operation that caused it, before the change has finished being stored.
Queued
After the change has been stored.
In immediate mode the message can therefore reach you before the operation it describes has finished. If your integration needs the record complete, with every related row written and every list filled in, choose queued delivery, or treat the message as a signal and read the record back from the API before acting on it.
When Your Endpoint Cannot Be Reached
A delivery is successful when your endpoint answers with a 2xx status within 10 seconds. Everything else counts as a failed attempt: an error status, a timeout, a refused connection.
Queued messages are retried automatically: the first attempt, then up to 10 more, spaced by the interval you configured on the hook. After the eleventh attempt the automatic delivery stops. The event is kept and marked as undelivered, and you can still send it yourself. See Re-sending an event.
An immediate message is sent once and is never retried.
Setting the retry interval
retry_countdown_config decides how long to wait before the next attempt. It takes a choice and its kwargs, where retry_count is the number of retries already made. It is therefore 0 when the wait before the first retry is worked out, 1 before the second, and so on.
fixed
seconds
Always seconds.
linear
base, limit (optional)
base * retry_count, capped at limit.
exponential
base, factor (default 1), limit (optional)
(base ** retry_count) * factor, capped at limit.
random
min_value, max_value
A random value in that range.
Because that count starts at 0, linear waits nothing at all before its first retry. fixed and random ignore the count entirely.
A sensible default is exponential backoff that starts at one minute and never waits longer than an hour:
That gives waits of 1, 2, 4, 8, 16 and 32 minutes, then 60 minutes before each remaining retry. A brief outage is caught within a minute, and an endpoint that stays down is given about five hours in total before the automatic attempts run out.
Set a limit whenever you choose exponential. Without one the waits keep doubling and the last attempts end up days apart.
Confirming a Delivery
On your own endpoint
Every request arrives as a POST with these headers:
Content-Type
application/json
X-Whisperer-Event
The event name, for example user_registered.
X-Whisperer-Signature
Proof that the request came from Akinon, in the form sha256=<hex digest>. Present on queued messages when the hook has a secret_key.
Your own headers
Anything you put in additional_headers, plus basic authentication if you configured it.
The event.uuid in the body identifies the event, not the attempt: every retry of the same event repeats it. Use it as your idempotency key, so a repeated delivery does not produce a second record or a second e-mail on your side.
Verify the signature. It is computed over the raw request body, before any parsing, using the same secret_key you chose when you registered the hook. Your own copy of that string is the one you verify with; if you have lost it, read the hook back with GET /whisperer/hooks/ or set a new one with PATCH.
A hook with no secret_key sends no signature header at all, so an endpoint that requires one should treat a missing header as a failed check rather than a pass. Immediate messages are not signed, so protect that address with the basic authentication in authentication_config instead.
On the Akinon side
Every attempt at a queued delivery is recorded: what was sent, when, what your endpoint answered, and how long it took. You can read these records yourself instead of opening a support ticket:
Available filters: uuid, event_type, delivered, response_http_status, object_id, content_type, webhook, and created_date with the gt, gte, lt and lte suffixes.
Each record answers a different half of "did you really send it, and what happened":
uuid
The event.uuid your endpoint received. This is what ties a record here to a line in your own log.
request_datetimes
The timestamp of every attempt, most recent first. This is the proof of what was sent and when.
retry_count
How many attempts have been made so far.
delivered
true once an attempt was answered with a 2xx.
response_http_status
The status your endpoint answered with on the last attempt.
response_content
The body your endpoint answered with. Usually where the reason for a failure is.
response_time
How long that attempt took. Compare it against the 10-second limit.
request_payload
The exact body that was sent, and that every retry repeats.
object_id
The identifier of the record the event is about, the same value as the identifier carried in the payload.
webhook
The hook it was sent through, including its target_url.
So a delivery you cannot find in your own logs falls into one of three cases: there is no record here at all, and the event was never raised; there is a record with a response_http_status your endpoint returned, and the request did arrive; or delivered is false with a timeout or connection error, and the request never got through.
Immediate messages are not recorded this way. There is no stored attempt to look up afterwards, which is another reason to prefer queued delivery for anything you need to audit.
Re-sending an event
Once your endpoint is healthy again, an event that was given up on can be sent again. The stored body is replayed unchanged:
You get 200 when the delivery succeeds. You get 406 when it fails, when the event had already been delivered, or when it is still inside its automatic retry window. Add "force": true to send it anyway.
A Complete Example
Suppose you want your CRM to be told whenever a customer creates an account.
1. Register the hook, so queued deliveries know where to go and how to sign themselves:
2. Create the definition that turns the event on, in queued mode:
3. Register a customer on the storefront. Your endpoint receives:
The payload is shortened here for readability; the full set of fields is under UserRegisteredEvent.
4. Handle it. Verify X-Whisperer-Signature against your secret_key, and stop if it does not match. Check whether you have already seen event.uuid, and if you have, answer 200 and do nothing else. Otherwise write the job to your own queue and answer 200 straight away. The CRM call happens after you have answered, not before.
5. Confirm it arrived, using the uuid from the body:
delivered: true with a single entry in request_datetimes means it went out once and you accepted it. delivered: false with a growing request_datetimes and retry_count means the platform is still working through its eleven attempts, and response_http_status and response_content say what your endpoint answered each time.
Available Commerce Webhook Events
In most payloads the pk field is the identifier of the record the event is about.
basket_offer_created
A campaign, coupon or discount code is created.
basket_offer_updated
A campaign, coupon or discount code is changed.
user_logged_in
A customer signs in.
user_registered
A customer creates an account.
user_updated
A customer's details change. Signing in updates the last-login date, so this event follows a sign-in as well.
conversation_replied
The seller writes in a question or a private message, including the first message of a private message the seller opens.
1. BasketOfferCreatedEvent
event_name: basket_offer_created
This event is triggered when a new campaign, coupon, or discount code is created.
Payload Structure
2. BasketOfferUpdatedEvent
event_name: basket_offer_updated
This event is triggered when a campaign, coupon, or discount code is updated. The payload structure is identical to BasketOfferCreatedEvent.
3. UserLoggedInEvent
event_name: user_logged_in
This event is triggered when a user logs into the Commerce system.
Payload Structure
4. UserUpdatedEvent
event_name: user_updated
This event is triggered when a user updates their information in the Commerce system. Since the last login date is updated when a user logs in, this event is also triggered when a user successfully logs into the system. The payload structure is identical to UserLoggedInEvent.
5. UserRegisteredEvent
event_name: user_registered
This event is triggered when a new user registers in the Commerce system. The payload structure is identical to UserLoggedInEvent.
6. ConversationRepliedEvent
event_name: conversation_replied
A conversation is a thread between a customer and a seller: a question about a product, or a private message, optionally about an order item. This event is triggered when the seller replies to such a thread, including the first message of a private message the seller opens from the panel. A message written by the customer does not trigger it. Reviews cannot be replied to, so they never trigger it.
The payload is the whole conversation, not just the new reply: the customer it belongs to, the seller who replied, the item it is about, every message in the thread, and its rating and moderation status. is_answered is true. The order of message_set is not guaranteed, so do not take the last entry as the reply: use each message's created_date and content_type to find it. The reply that caused the event is the most recent message whose content_type is datasource. The payload is read when the webhook is delivered, so a message written in the meantime is already part of it.
The conversation is identified by id here rather than pk.
Payload Structure
Fields worth noting:
conversation_type: in practicemessageorquestion. A review cannot be replied to, so this event never carriesreview.item_contentanditem_object: what the conversation is about.item_contentisproductwhen the customer asked about a product, andorderitemwhen it is about a line in an order;item_objectthen carries that record (for an order item:pk,product,statusandorder_number). Both arenullfor a conversation that is not attached to anything.is_public: whether the thread is shown on the storefront, for example under a product. For a question created after moderation was introduced, it becomestrueonly when a moderator approves it; a question created before that keeps its earlier value, withstatus: null, until a moderator approves or rejects it. A private message created after moderation was introduced is alwaysfalse; an older one keeps the value it had, since visibility could then be set by hand. The seller can reply to a question that is still waiting for moderation, so a reply to a pending question fires this event withis_public: falseandstatus: "pending".status: the moderation state of a question:pending,approvedorrejected. It isnullfor a private message, which is not moderated, and for a conversation created before moderation was introduced until a moderator decides on it.rating: the star rating, which only reviews carry. It isnullin this event.
Last updated
Was this helpful?

