Receive E-Invoicing Webhooks

Get notified when an invoice is signed, fails in the background, is delivered, or is acknowledged, and verify that each event came from Duplo.

Most e-invoicing calls answer in their own response: create, update, a synchronous submit, and a transmit all return the result directly. Some outcomes arrive later, after the call that started them has returned. Duplo sends a webhook for each of those, so you do not have to poll for them. The sign endpoint is the exception: it returns the signed invoice and also sends INVOICE_SIGNED, the same event a handed-off submit sends, so you can handle signing in one place.

EventWhen it is sent
INVOICE_SIGNEDNRS signed the invoice, either through the sign endpoint or after a submit that was handed off to background processing. The IRN is now valid. A submit that signs synchronously returns the signed invoice in its response instead
INVOICE_VALIDATION_FAILEDBackground validation failed. The invoice is back to created, so you can edit it and submit again. Sent once per failure, so one invoice can produce several
INVOICE_SIGN_FAILEDBackground signing failed for good and the invoice is rejected, including when the e-invoicing charge was declined. Recover with the resubmit endpoint
INVOICE_TRANSMITTEDNRS confirmed delivery to the buyer after a transmit whose outcome was not known when the call returned
INVOICE_ACKNOWLEDGEDThe buyer acknowledged an invoice you sent

Treat any other event_type value as one you do not handle yet: acknowledge it and move on rather than failing the delivery.

Setting up your endpoint

In Duplo Dashboard, open Settings › Developer API, scroll to Webhook, enter your URL, and click Save. When you save, Duplo sends a GET to the URL and keeps it only if that returns a 2xx response.

The Webhook section of the Developer API page in Duplo Dashboard, with the webhook URL field and the Save button

Test and live mode each keep their own URL, and saving sets the one for the mode your business is in at the time, so save it again after you go live. Events for an invoice go to the URL saved for that invoice's mode, and only while your business has an active API key in that mode.

Your endpoint must:

  • Use HTTPS on the default port, at a domain that resolves only to public IP addresses.
  • Answer with a 2xx without redirecting. Neither the check on save nor a delivery follows redirects.
  • Respond within 5 seconds. Store the event and return, then do the real work afterwards.

Parsing an event

Every event is a JSON POST with the same envelope:

Event body
{
  "event_type": "INVOICE_SIGN_FAILED",
  "data": {
    "invoiceId": "9c1f3b2a-77e4-4c1d-9b6a-2f5d8e0a4c73",
    "invoiceReferenceNumber": "DUP00000001-2A3A045D-20240123",
    "invoiceNumber": "INV-2024-001",
    "status": "rejected",
    "nrsStatus": "rejected",
    "transmissionStatus": "not_sent",
    "environment": "sandbox",
    "occurredAt": "2026-11-06T10:00:00.000Z",
    "reason": { "code": "nrs_sign_rejected" }
  }
}
FieldWhat it holds
event_typeOne of the event names at the top of this page
dataA snapshot of the invoice when the event happened: its IDs, status, nrsStatus, and transmissionStatus
data.environmentsandbox for an invoice made with a test key (sk_test_…), live for a live key (sk_live_…)
data.occurredAtWhen the change happened, in UTC
data.reasonA machine-readable code on failure events, and null on the others

The body has no event ID. Each event's ID arrives in the x-duplo-delivery-id header instead.

Events can arrive out of order, for example a retried older event after a newer one. Ignore an event that is older than the state you already hold, and when in doubt, read the invoice back with Get invoice, which is always current.

Each request also carries these headers:

HeaderValue
x-duplo-delivery-idUnique per event. Retries of the same event reuse it, so use it to drop duplicates
x-duplo-eventThe event name, the same as the body's event_type
x-duplo-timestampUnix time in seconds when this attempt was signed
x-duplo-signatureOne or more v1=<hex> signatures, separated by commas

Verifying the signature

Every delivery is signed, so check the signature before you trust the body. Each v1 value is an HMAC-SHA256 of <x-duplo-delivery-id>.<x-duplo-timestamp>.<raw request body>, keyed with one of your secret API keys for the event's data.environment: sk_test_… for sandbox and sk_live_… for live. Your public key (pk_…) is never used.

Duplo signs with every active secret key in that mode, plus any key revoked or deactivated in the last 24 hours, and sends one v1 value per key. A delivery therefore verifies with whichever key you hold, including while you rotate keys. Accept it if any v1 value matches.

  1. Read the raw request bytes. Parsing the JSON and serializing it again changes them.
  2. Reject the request if x-duplo-timestamp is more than 5 minutes from your clock.
  3. Compute the HMAC and compare it with each v1 value in constant time.
  4. Return a 2xx quickly, including for a duplicate you have already processed.
import express from "express";
import { createHmac, timingSafeEqual } from "crypto";

function isValidDuploWebhook(
  rawBody: Buffer,
  headers: Record<string, string>,
  secretKey: string,
): boolean {
  const id = headers["x-duplo-delivery-id"];
  const timestamp = Number(headers["x-duplo-timestamp"]);
  if (!id || !Number.isFinite(timestamp)) return false;
  if (Math.abs(Date.now() / 1000 - timestamp) > 300) return false;

  const expected = createHmac("sha256", secretKey)
    .update(`${id}.${timestamp}.${rawBody.toString("utf8")}`)
    .digest();

  return (headers["x-duplo-signature"] ?? "")
    .split(",")
    .map((part) => Buffer.from(part.trim().replace(/^v1=/, ""), "hex"))
    .some(
      (given) =>
        given.length === expected.length && timingSafeEqual(given, expected),
    );
}

const app = express();

// Read this route's body as raw bytes, ahead of any global express.json().
app.post(
  "/webhooks/duplo",
  express.raw({ type: "application/json" }),
  (req, res) => {
    const headers = req.headers as Record<string, string>;
    if (!isValidDuploWebhook(req.body, headers, process.env.DUPLO_SECRET_KEY!)) {
      return res.sendStatus(401);
    }
    const event = JSON.parse(req.body.toString("utf8"));
    // Store the event unless this x-duplo-delivery-id was already seen, then queue the work.
    res.sendStatus(200);
  },
);

app.use(express.json());

The mistakes that most often break verification are parsing the JSON before verifying it, using the other mode's secret key or the public key, checking only the first v1 value, and comparing with == or === instead of a constant-time function.

Retries

Delivery is at least once. A response other than 2xx, or no response within 5 seconds, is retried after 30 seconds, and the wait doubles after each failed attempt, for up to 8 attempts in all. The last attempt comes about an hour after the first. Every retry is signed again with a fresh timestamp but keeps the same x-duplo-delivery-id, so the same event can reach you more than once.

Because a delivery can still be missed, for instance while your endpoint is down for longer than the retries last, do not rely on webhooks alone for anything that matters. Read the invoice back, or list your invoices, to reconcile on a schedule.

How is this guide?

Last updated on

On this page

Need help? Visit our help center