Webhooks

Receive invoice lifecycle events at your endpoint. Configure the URL and signing secret in the dashboard. Use HTTPS in production. HTTP is allowed for local testing.

Same compliance fields as the API

invoice.reported / invoice.cleared payloads include data.zatca_compliant, zatca_warnings, and resubmit. If resubmit: false, do not resend the same invoice_number/uuid. See Responses.
Integrators implement an HTTP(S) endpoint on their side. Esnad POSTs JSON when invoice status changes. Delivery logs and manual retries are available in the dashboard.

Overview

  • Configure a single webhook URL per tenant in the dashboard (use HTTPS in production).
  • We send a POST with a JSON body for each event.
  • Every request includes X-ZATCA-Event (event type) and X-ZATCA-Delivery-ID (unique delivery id — use for idempotency).
  • Optionally set a signing secret; we then send X-ZATCA-Signature: sha256=<hmac_hex> (HMAC-SHA256 of the raw body).
  • Retries: A delivery that returns a non-2xx status or times out is tried again, up to 5 attempts in total. After the first failure we wait 1 minute, then 5 minutes, 15 minutes, and 1 hour. A worker checks every minute. After the fifth attempt the event is permanently failed. Retry it from the dashboard; that sends the same X-ZATCA-Delivery-ID again.

Event types

EventWhen
invoice.queuedInvoice signed and accepted; ZATCA submission is queued (API may have returned HTTP 202).
invoice.reportedSimplified invoice (or credit/debit note) reported to ZATCA (B2C). Check data.zatca_compliant — if false, ZATCA accepted with warnings; do not resubmit.
invoice.clearedStandard invoice (or credit/debit note) cleared by ZATCA (B2B). Same compliance fields as reported — accepted ≠ fully compliant when warnings are present.
invoice.failedSubmission permanently failed after retries or a non-retryable validation error (see data.error).
webhook.testTriggered by "Send test event" in the dashboard.
cert.expiringEGS unit certificate expiring within 30/14/7/1 days or expired.

Invoice events use envelope version api_version: "2026-07-24". invoice.submitted is not emitted (reserved type only).

Payload examples

Amounts in data are SAR numbers. prepaid and payable are included on every invoice event (payable is total minus prepaid). xml_stamped is true when ZATCA returned a cleared XML. signed_xml_url and pdf_url are API paths (authenticate with your API key). metadata is your own key-value data from create, or null. A loan_reference value inside it is printed on the PDF as Loan: …. qr_code is present for simplified invoices when signed XML is available. Invoice payloads also include zatca_compliant, zatca_warning_count, zatca_warnings, and resubmit. Event names stay reported/cleared even when warnings exist — check zatca_compliant and resubmit: false (do not resend the same invoice_number/uuid). On invoice.failed, resubmit is true: issue a new invoice number. Do not treat warnings as invoice.failed.

invoice.queued

{
  "event": "invoice.queued",
  "api_version": "2026-07-24",
  "occurred_at": "2026-07-24T10:15:30.000Z",
  "tenant_id": "ten_01hxyz…",
  "data": {
    "invoice_id": "inv_01hxyz…",
    "uuid": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
    "invoice_number": "INV-2026-0042",
    "metadata": { "loan_reference": "LN-2026-01482", "contract_id": "C-100" },
    "status": "queued",
    "invoice_type": "standard",
    "document_type": "invoice",
    "egs_unit_id": "egs_01hxyz…",
    "environment": "sandbox",
    "reference_uuid": null,
    "subtotal": 1000,
    "vat": 150,
    "total": 1150,
    "prepaid": 0,
    "payable": 1150,
    "qr_code": null,
    "signed_xml_url": "/v1/invoices/inv_01hxyz…/xml",
    "pdf_url": "/v1/invoices/inv_01hxyz…/pdf",
    "xml_stamped": false,
    "reported_at": null,
    "cleared_at": null,
    "report_deadline": null,
    "zatca_status": null,
    "retry_count": 0,
    "next_retry_at": "2026-07-24T10:16:30.000Z",
    "zatca_compliant": true,
    "zatca_warning_count": 0,
    "zatca_warnings": [],
    "resubmit": true,
    "error": null
  }
}

invoice.cleared

{
  "event": "invoice.cleared",
  "api_version": "2026-07-24",
  "occurred_at": "2026-07-24T10:15:45.000Z",
  "tenant_id": "ten_01hxyz…",
  "data": {
    "invoice_id": "inv_01hxyz…",
    "uuid": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
    "invoice_number": "INV-2026-0042",
    "metadata": { "loan_reference": "LN-2026-01482", "contract_id": "C-100" },
    "status": "cleared",
    "invoice_type": "standard",
    "document_type": "invoice",
    "egs_unit_id": "egs_01hxyz…",
    "environment": "sandbox",
    "reference_uuid": null,
    "subtotal": 1000,
    "vat": 150,
    "total": 1150,
    "prepaid": 0,
    "payable": 1150,
    "qr_code": null,
    "signed_xml_url": "/v1/invoices/inv_01hxyz…/xml",
    "pdf_url": "/v1/invoices/inv_01hxyz…/pdf",
    "xml_stamped": true,
    "reported_at": null,
    "cleared_at": "2026-07-24T10:15:44.000Z",
    "report_deadline": null,
    "zatca_status": "CLEARED",
    "zatca_compliant": true,
    "zatca_warning_count": 0,
    "zatca_warnings": [],
    "resubmit": true,
    "retry_count": 0,
    "next_retry_at": null,
    "error": null
  }
}

invoice.reported

{
  "event": "invoice.reported",
  "api_version": "2026-07-24",
  "occurred_at": "2026-07-24T10:16:00.000Z",
  "tenant_id": "ten_01hxyz…",
  "data": {
    "invoice_id": "inv_01habc…",
    "uuid": "7c9e6679-7425-40de-944b-e07fc1f90ae7",
    "invoice_number": "SIM-2026-0099",
    "metadata": { "loan_reference": "LN-2026-01482", "contract_id": "C-100" },
    "status": "reported",
    "invoice_type": "simplified",
    "document_type": "invoice",
    "egs_unit_id": "egs_01hxyz…",
    "environment": "sandbox",
    "reference_uuid": null,
    "subtotal": 50,
    "vat": 7.5,
    "total": 57.5,
    "prepaid": 0,
    "payable": 57.5,
    "qr_code": "AQlTYW1wbGUuLi4=",
    "signed_xml_url": "/v1/invoices/inv_01habc…/xml",
    "pdf_url": "/v1/invoices/inv_01habc…/pdf",
    "xml_stamped": false,
    "reported_at": "2026-07-24T10:15:59.000Z",
    "cleared_at": null,
    "report_deadline": "2026-07-25T10:15:00.000Z",
    "zatca_status": "REPORTED",
    "zatca_compliant": true,
    "zatca_warning_count": 0,
    "zatca_warnings": [],
    "resubmit": true,
    "retry_count": 0,
    "next_retry_at": null,
    "error": null
  }
}

invoice.failed

{
  "event": "invoice.failed",
  "api_version": "2026-07-24",
  "occurred_at": "2026-07-24T12:00:00.000Z",
  "tenant_id": "ten_01hxyz…",
  "data": {
    "invoice_id": "inv_01hfail…",
    "uuid": "9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d",
    "invoice_number": "INV-2026-0100",
    "metadata": null,
    "status": "failed",
    "invoice_type": "standard",
    "document_type": "invoice",
    "egs_unit_id": "egs_01hxyz…",
    "environment": "sandbox",
    "reference_uuid": null,
    "subtotal": 1000,
    "vat": 150,
    "total": 1150,
    "prepaid": 0,
    "payable": 1150,
    "qr_code": null,
    "signed_xml_url": "/v1/invoices/inv_01hfail…/xml",
    "pdf_url": "/v1/invoices/inv_01hfail…/pdf",
    "xml_stamped": false,
    "reported_at": null,
    "cleared_at": null,
    "report_deadline": null,
    "zatca_status": null,
    "retry_count": 0,
    "next_retry_at": null,
    "zatca_compliant": false,
    "zatca_warning_count": 0,
    "zatca_warnings": [],
    "resubmit": true,
    "error": {
      "code": "ZATCA_VALIDATION_FAILED",
      "message": "ZATCA validation failed (BR-CUSTOM-VALIDATION-01)",
      "retryable": false,
      "zatca_errors": [
        {
          "zatca_code": "BR-CUSTOM-VALIDATION-01",
          "zatca_message": "The seller VAT registration number must not match the buyer VAT registration number."
        }
      ]
    }
  }
}

webhook.test

Compact payload (no api_version envelope).

{
  "event": "webhook.test",
  "message": "Test delivery from Esnad API",
  "timestamp": "2026-07-24T10:20:00.000Z"
}

cert.expiring

Compact payload. alert_type is one of 30_days, 14_days, 7_days, 1_day, expired.

{
  "event": "cert.expiring",
  "egs_unit_id": "egs_01hxyz…",
  "unit_name": "Main POS",
  "alert_type": "30_days",
  "cert_expires_at": "2026-08-23T00:00:00.000Z",
  "days_until_expiry": 30
}

Verifying the signature

If you set a webhook secret, verify the X-ZATCA-Signature header using the raw request body (UTF-8) and your secret. Use constant-time comparison to avoid timing attacks. Deduplicate using X-ZATCA-Delivery-ID.

// Node.js example
const crypto = require('crypto');
function verifySignature(rawBody, signatureHeader, secret) {
  const expected = 'sha256=' + crypto.createHmac('sha256', secret).update(rawBody).digest('hex');
  return crypto.timingSafeEqual(Buffer.from(signatureHeader), Buffer.from(expected));
}