Invoice Ninja webhooks in production: duplicates, ordering, retries and timeouts
This guide covers the problems Invoice Ninja webhooks cause in production and how to handle each one. What Invoice Ninja sends is on the Invoice Ninja webhooks overview, every event key is on Invoice Ninja webhook events, and the secret header check is on Verify Invoice Ninja webhooks.
Invoice Ninja's public API reference documents the subscription fields but not how deliveries behave. Invoice Ninja is open source, so the delivery details here come from its version 5 server code. That code can change between releases without a docs update, so check them against your own version if you self-host.
At a glance
| Problem | What to do | With Event Gateway |
|---|---|---|
| Timeouts | Return a 200 within 30 seconds; process in a background job | Accepts the delivery at once, then queues it for your service |
| Duplicates | Upsert on the record's id and compare updated_at | Can drop repeats before they reach your handler |
| Ordering | Ignore bodies older than what you've stored | Logs every event, so you can see what arrived when |
| Retries | Never answer 404, 405 or 410; reconcile after incidents | Accepts deliveries while your service is down and replays them |
| Choosing events | Give each subscription its own path or ?event= value | Filters and routes on the path or query string |
| Testing | Create real records, and resend with the retry call | Forwards to localhost and replays past events |
| Other limits | Re-read records that move money; check your plan and version | Checks the secret header on every request |
Invoice Ninja webhook timeouts and slow handlers
Invoice Ninja allows 10 seconds to connect and 30 seconds for the whole request. Store the record, return a 200, and do the rest in a background job.
Why it happens: A request that hits either limit counts as a connection failure, so Invoice Ninja sends it again, even if your handler went on to finish. Work that fails before you respond is worse: a 500 isn't retried, so the event is gone.
Fix it in your handler:
- Check the secret header, store the body and return a
200. - Process the record in a worker. See why to process webhooks asynchronously.
- Keep calls to other services out of the request path.
With Event Gateway: Hookdeck accepts each Invoice Ninja delivery as it arrives, then queues it and delivers it to your service with its own retries. Your handler's speed no longer affects Invoice Ninja's timeout.
Duplicate Invoice Ninja webhooks
The same record can reach you more than once, and there's no delivery ID to spot it with. Upsert on the record's id and compare updated_at.
Why it happens: A delivery that succeeds on your side but times out on Invoice Ninja's is sent again. Separately, update_* events fire whenever a record is saved with changes, so one action in the app can produce several deliveries, and a single action can fire more than one event, such as update_invoice and sent_invoice.
Fix it in your handler:
- Key your writes on the record's
id, and use the event name,idandupdated_attogether as an idempotency key for side effects. See our guide to webhook idempotency. - Treat the body as the record's current state rather than a change to apply.
- Return a
200for a repeat, so a duplicate doesn't look like a failure.
With Event Gateway: Deduplication can compare the fields you choose, such as id and updated_at, and drop repeats within a time window before they reach your handler.
Out-of-order Invoice Ninja webhooks
Invoice Ninja makes no promise about order, and the code gives events different delays. Compare updated_at with what you've stored before you apply a body.
Why it happens: Each event is a queued job. Payment events wait 20 to 25 seconds in the queue, client events 2 seconds and most others no time at all, so an event from just after a payment can arrive before its create_payment. Retries add further delay. The job also reloads the record when it runs, so the body shows the record at send time. A create_invoice body can already hold later edits.
Fix it in your handler:
- Store
updated_atwith each record, and ignore a body with an older value. It's in whole seconds, so treat an equal value as new. - Handle a child record that arrives first, such as a payment for an invoice you haven't stored, by fetching the parent from the API.
With Event Gateway: Hookdeck logs every event and attempt, so you can see the order things arrived in when you're debugging.
Invoice Ninja webhook retries
Invoice Ninja retries connection errors, timeouts and 429, up to 5 tries in all. It drops every other failure, and a 404, 405 or 410 also archives the subscription.
Why it happens: Retries come about 10 to 15 seconds, 30 to 40 seconds, 1 minute and 3 minutes apart, so the whole schedule lasts about 5 minutes. Every 5xx and every other 4xx is logged and dropped at once. Invoice Ninja treats 404, 405 and 410 as a dead URL and soft-deletes the subscription, the same state as archiving, so it stops sending. A route that only accepts POST while the subscription uses PUT, a deploy that briefly removes the route, or a proxy that answers 404 for an unknown path is enough.
Fix it in your handler:
- Use
200for success,401for bad credentials and400for a bad body. Use429only when you want a retry. - Accept the subscription's method on the route, and check that your framework and proxies can't answer
404,405or410for it. - After deploys and incidents, check Invoice Ninja's system log and look for archived webhooks. Restore one in the app, or with
POST /api/v1/webhooks/bulkand therestoreaction. - Reconcile against the Invoice Ninja API after an outage, because dropped events aren't sent again.
With Event Gateway: Hookdeck accepts Invoice Ninja's deliveries while your service is down and keeps them, so a 500 from your service becomes a retry on a schedule you control, and a missing route shows up as a failed delivery you can replay. If a subscription uses PUT, allow PUT on the source before you save the subscription, because the source type pre-selects POST.
Choosing which Invoice Ninja events to handle
A subscription has exactly one event, and the event isn't in the request. Create a subscription for each event you need, each with its own path or ?event= value.
Why it happens: The event key belongs to the subscription, and the body is just the record. Invoice Ninja adds no event header or field, so a single URL can't tell a create_invoice from an update_invoice.
Fix it in your handler:
- Route on the URL, such as
https://example.com/webhooks/invoice-ninja?event=create_, and keep a table of which subscription points where.invoice - Start with the events that drive your workflow, such as
sent_invoice,late_invoice,create_paymentandapprove_quote.late_invoicecomes from a daily check, for invoices with a balance whose due date was the day before. - Don't rely on
expired_quote. It's a valid key, but the v5 server has no active code that sends it. Compare a quote'sdue_dateyourself instead.
With Event Gateway: Hookdeck filters can route on the path or query string, so one source can send each subscription's events to a different destination.
Testing Invoice Ninja webhooks
Invoice Ninja documents no test event and publishes no example deliveries, so trigger real events on a test company and keep what you receive as fixtures.
Why you need a plan: The body is whatever the record's transformer produces, so you can't see the shape in advance. On the hosted service, a webhook on an unpaid account never fires, which looks exactly like a broken endpoint.
Test it safely:
- Use a paid hosted account or a self-hosted install. Target URLs on private addresses are rejected, so use a public URL or a tunnel.
- Create or edit a record in the app, and log the body for each event you handle before you write a parser for it.
- Resend one record with
POST /api/v1/webhooks/{id}/retry, passingentityandentity_id. It's in the server's routes but not in the API reference, and it sends the record as it is now. - Read the outcome in Invoice Ninja's system log, which records each delivery's result.
With Event Gateway: The Hookdeck CLI receives webhooks on your machine without a public server, and you can replay past events to your handler as you change it.
Other Invoice Ninja webhook limits
Webhooks aren't signed, so plan for what a leaked header value can do. Check your plan and your server version too.
A static header, not a signature. The custom header is the same on every request, so anyone who learns it can send convincing invoices or payments to your endpoint, and a captured request can be replayed. Use a long random value over HTTPS. For payments and anything else that moves money, re-read the record from the Invoice Ninja API by id before you act on it.
Plan and permissions. Only admins on an account with the API feature can create subscriptions, and the hosted service only sends webhooks for paid accounts.
No source IPs. None are published, and self-hosted installs send from their own host, so you can't allowlist by address.
Behaviour depends on your version. If you self-host, delivery works the way your installed version's code does, so re-check it when you upgrade.
A separate webhook on Subscriptions. Subscription products have their own webhook setting, which fires when a client signs up through the link. It's configured apart from the API webhooks in this guide.
With Event Gateway: Hookdeck's Invoice Ninja source type compares the header you name with the exact value you enter, and records a request without it as failed verification, so it never reaches your destination.
Keep a failing deploy from losing Invoice Ninja events.
Event Gateway checks your secret header, accepts each Invoice Ninja delivery as it arrives and queues it, so a 500 from your service becomes a retry instead of a dropped event.