# Mautic webhooks in production: duplicates, ordering, retries and timeouts

Agent skill: `npx skills add hookdeck/webhook-skills --skill mautic-webhooks` ([details](https://hookdeck.com/webhooks/mautic/skill))

This guide covers the problems Mautic webhooks cause in production and how to handle each one. Mautic's webhook docs carry a banner saying they need a major update, and they say little about delivery behaviour, so several answers here come from [Mautic's sender code](https://github.com/mautic/mautic/blob/7.x/app/bundles/WebhookBundle/Model/WebhookModel.php), read at version 7, and the guide says where that's the case. What Mautic sends and how to set it up is on the [Mautic webhooks](/webhooks/mautic) overview, every event type is on [Mautic webhook events](/webhooks/mautic/events), and signature verification code is on [Verify Mautic webhooks](/webhooks/mautic/verify).

## At a glance

| Problem | What to do | With Event Gateway |
| --- | --- | --- |
| [Timeouts](#timeouts) | Store the event, return a 2xx and process it afterwards | Accepts the delivery at once, then queues it for your service |
| [Retries](#retries) | Choose the delivery mode deliberately; don't return `410`; watch for unpublished webhooks | Stores each delivery and retries to your service on your schedule |
| [Duplicates](#duplicates) | Build a key from the event type, the object's ID and `timestamp` | Drops repeats based on the fields you choose |
| [Ordering](#ordering) | Compare stored state or `timestamp` before you apply a change | Delivers at a rate your service can handle |
| [Choosing events](#choosing-events) | Know what each event leaves out; don't rely on email opens | Filters and routes on the body |
| [Testing](#testing) | Trigger a real event as well as Send Test Payload | Forwards to localhost and replays past events |
| [Other limits](#other-limits) | Loop over every key and item; check field names against a real delivery | Verifies the signature and logs every delivery |

## Mautic webhook timeouts and slow handlers {#timeouts}

Store the event, return a 2xx and do the work afterwards. Mautic's docs state no timeout, so don't plan around one.

**Why it happens:** In real-time mode, Mautic's source sends the request while it handles the action that caused it, so a slow endpoint slows Mautic too. Its config has a `webhook_timeout` setting of 15 seconds, but the sender code we read doesn't apply it. Check how your own version behaves before you rely on that value.

**Fix it in your handler:**

1. Verify the signature, store every item in the request and respond straight away. See [why to process webhooks asynchronously](/webhooks/guides/why-implement-asynchronous-processing-webhooks).
2. Keep the request path free of calls to other services.
3. If real-time delivery slows your Mautic instance, consider queued mode, which sends from a cron job rather than during the action.

**With Event Gateway:** Hookdeck accepts each Mautic delivery immediately, then queues it and delivers it to your service at a rate it can handle. Your handler can take as long as it needs without holding up Mautic.

## Mautic webhook retries and unpublished webhooks {#retries}

Real-time deliveries aren't retried. Queued deliveries are retried by later cron runs, and a webhook that keeps failing gets unpublished. Mautic's docs cover none of this, so all of it comes from its source.

**Why it happens:**

* **Real-time mode.** A failed delivery is logged and dropped, because Mautic never stored the event.
* **Queued mode.** After a non-2xx response, the items stay in the database and later cron runs send them again once `webhook_retry_delay` has passed, an hour by default. After a connection error, the next run sends them again. The code we read sets no maximum number of retries.
* **Unpublishing.** A `410` unpublishes the webhook at once. Mautic also unpublishes a webhook when none of the last 100 entries in its log (`webhook_disable_limit`) is a success, or fewer entries if the log is shorter. It skips this if `disable_auto_unpublish` is set or the webhook was edited in the last two days.

**Fix it in your handler:**

1. Pick the mode deliberately. Real-time delivery is immediate with no retries, and queued delivery retries but adds the cron interval to every event.
2. Return `410` from your webhook route only if you mean "stop sending".
3. Check that your webhooks are still published after any outage.
4. After an outage in real-time mode, reconcile from the [Mautic API](https://devdocs.mautic.org/en/5.x/rest_api/contacts.html) for the objects you care about.

**With Event Gateway:** Hookdeck answers Mautic with a 2xx as soon as it has stored the request, then [retries](/docs/retries) towards your service on your schedule. Failures on your side no longer count against the webhook or lose real-time events.

## Duplicate Mautic webhooks {#duplicates}

Deduplicate on each item, not each request, using a key you build yourself. Mautic sends no event ID.

**Why it happens:** After a failed queued request, Mautic's source sends the same items again, and they can land in a different batch from the first attempt. If your handler stored some items before it failed, the retry repeats them.

**Fix it in your handler:**

1. Build a key from the event type, the main object's ID (contact, submission, company) and the item's `timestamp`, which is when Mautic queued the event and doesn't change between attempts. It's only accurate to the second, so two changes to one contact in the same second share a key.
2. Store processed keys with a unique constraint. See our [guide to webhook idempotency](/webhooks/guides/implement-webhook-idempotency).
3. Return a 2xx only once every item in the request is stored, so that a failure can't drop part of a batch.

**With Event Gateway:** Hookdeck's [deduplication](/docs/deduplication) can drop repeated requests based on the fields you choose. It works on whole requests, so keep per-item keys for batches.

## Out-of-order Mautic webhooks {#ordering}

Don't assume items arrive in the order they happened. Compare `timestamp` or your stored state before you apply a change.

**Why it happens:** In queued mode, the Order of the queued events setting makes batches chronological or reverse chronological. In Mautic's source, failed items also sort after fresh ones, so a retried item can arrive after a newer event about the same contact. Mautic's docs don't describe the order of real-time deliveries.

**Fix it in your handler:**

1. Use Chronological if you run queued mode and the order matters.
2. Store each object's latest `timestamp`, and skip an older item.
3. When only the current state matters, fetch the object from the Mautic API.

**With Event Gateway:** Hookdeck queues deliveries and sends them at a rate your service can handle, which reduces overlap between handlers. It doesn't restore the original order, so keep the timestamp check.

## Choosing Mautic events {#choosing-events}

Subscribe only to the events you process, and create one webhook per app or script, as Mautic recommends, so that each secret is exposed in as few places as possible.

**What to watch for:**

* `mautic.lead_post_save_new` means a contact was identified, not that a record was created. Mautic's source sends nothing for anonymous contacts on either save event.
* `mautic.email_on_open` depends on a tracking pixel. Mautic's docs say proxies and bots can load it, so don't drive critical logic from it. In Mautic's source this event sends a `stat` object, although the docs point to the properties of `mautic.email_on_send`.
* Deletion events carry the ID in `id`, because the `contact` or `company` object that comes with them has a null `id`.
* `mautic.lead_list_change` covers segment membership. Mautic's sender registers it, although the docs don't list it.

**With Event Gateway:** Hookdeck can [filter](/docs/filters) and route on the body, so you can send each event type to the service that needs it.

## Testing Mautic webhooks {#testing}

Use Send Test Payload to check that the URL and signature work, then trigger a real event to see a real body.

**Why it happens:** In Mautic's source, the button posts static fixture files rather than anything from your instance. Their data is old, and the shape differs from a real delivery in several ways:

* `mautic.form_on_submit`, `mautic.page_on_hit` and `mautic.email_on_open` arrive as a bare object rather than an array, with no `timestamp`.
* The `mautic.lead_points_change` fixture has no `points` object.
* Company events, `mautic.lead_company_change`, `mautic.email_on_send`, `mautic.sms_on_send` and `mautic.lead_list_change` have no fixture and are left out, so a webhook with only those selected posts an empty `[]`.

**How to test:**

1. Click Send Test Payload to check the URL and signature. It signs with the secret currently in the form.
2. Submit a form or edit a contact to send a real event. Mautic's docs describe no way to resend a delivery, so keep a copy of the body.
3. Mautic 7 rejects private network addresses unless they're in the `webhook_allowed_private_addresses` setting, so a `localhost` URL won't work without it. Use a public tunnel instead.

**With Event Gateway:** The Hookdeck CLI forwards events to localhost, and you can replay past events from the dashboard while you work on your handler.

## Other Mautic webhook limits {#other-limits}

**Batched bodies.** Each top-level key is an event type holding an array. A real-time request has one key and one item, and a queued request can hold several of each. In Mautic's source, each request holds up to 10 items by default (`webhook_limit`), and a cron run keeps sending until the queue is empty or `webhook_time_limit` passes, 600 seconds by default. Loop over every key and every item.

**Unreliable docs.** Mautic's own banner says its webhook pages need a major update. They also disagree with its source in places: the `mautic.lead_post_delete` page names the object `company`, while the sender uses `contact`. Check field names against a real delivery from your version.

**No replay protection.** The signature covers only the body, with no signed timestamp, so a captured request stays valid. Keep the endpoint on HTTPS and rely on your idempotency keys.

**Self-hosted senders.** Every installation is its own sender, so there's no IP list to allow. Mautic's source sets `X-Origin-Base-URL` to the instance's URL. The administrator controls the settings above, so check yours rather than assuming the defaults.

**With Event Gateway:** Hookdeck verifies the signature, then gives you one log of every request, so if your handler fails partway through a batch you can fix it and replay the whole request.