{"product_id":"ksef-e-invoice-exception-handling-n8n-webhooks-gmail","title":"KSeF E-Invoice Exception Handling n8n Webhooks + Gmail","description":"\u003ch3\u003eKSeF e-Invoice Exception Handling for n8n: Webhooks + Gmail alerts\u003c\/h3\u003e\n\u003cp\u003eAutomate KSeF e-invoice intake, validation, retry-safe status checks, and exception routing in n8n—using a token-protected webhook and Gmail to send controlled internal summaries and aged recovery alerts for unresolved cases.\u003c\/p\u003e\n\n\u003ch3\u003eWhat this workflow does\u003c\/h3\u003e\n\u003cul\u003e\n  \u003cli\u003e\n\u003cb\u003eReceives invoice data securely\u003c\/b\u003e via a webhook that requires a \u003ci\u003eKSEF_INTAKE_TOKEN\u003c\/i\u003e (sent as \u003cb\u003ex-ksef-token\u003c\/b\u003e or through the synthetic fixture). Missing\/incorrect tokens return \u003cb\u003e401\u003c\/b\u003e.\u003c\/li\u003e\n  \u003cli\u003e\n\u003cb\u003eValidates before persistence\u003c\/b\u003e by checking required fields, basic XML shape, NIP checksums, caller-provided VAT-whitelist status, and supplied approval records—then stores the \u003cb\u003eexact JSON snapshot\u003c\/b\u003e and a \u003cb\u003eSHA-256 hash\u003c\/b\u003e.\u003c\/li\u003e\n  \u003cli\u003e\n\u003cb\u003eRoutes outcomes through lifecycle states\u003c\/b\u003e so one manual execution can handle submission, recovery, or fixture intake. Before any bundled adapter runs, it re-reads lifecycle state and writes a \u003cb\u003efail-stop durable intent row\u003c\/b\u003e.\u003c\/li\u003e\n  \u003cli\u003e\n\u003cb\u003eUses local mock submission for deterministic runs\u003c\/b\u003e, then appends lifecycle transitions, evidence, exceptions, and run summaries to \u003cb\u003efour n8n Data Tables\u003c\/b\u003e.\u003c\/li\u003e\n  \u003cli\u003e\n\u003cb\u003eChecks status before retrying\u003c\/b\u003e by querying the local mock status adapter. If the result is \u003cb\u003eUNKNOWN\u003c\/b\u003e, \u003cb\u003eERROR\u003c\/b\u003e, or non-authoritative, it keeps cases on hold without submitting.\u003c\/li\u003e\n  \u003cli\u003e\n\u003cb\u003eRetries only once\u003c\/b\u003e and only after an \u003cb\u003eauthoritative NOT_FOUND\u003c\/b\u003e.\u003c\/li\u003e\n  \u003cli\u003e\n\u003cb\u003eNotifies via Gmail\u003c\/b\u003e after persistence checks succeed: it sends controlled internal intake summaries and \u003cb\u003eaged-recovery alerts\u003c\/b\u003e for related unresolved records.\u003c\/li\u003e\n\u003c\/ul\u003e\n\n\u003ch3\u003eUse cases\u003c\/h3\u003e\n\u003cul\u003e\n  \u003cli\u003eProcess incoming KSeF e-invoice payloads from your SaaS and ensure invalid requests fail fast with 401.\u003c\/li\u003e\n  \u003cli\u003eRecover invoices after transient issues by querying status first, then retrying only when NOT_FOUND is authoritative.\u003c\/li\u003e\n  \u003cli\u003eMaintain an exception queue with evidence and lifecycle audit trails, with Gmail updates for aged recoveries.\u003c\/li\u003e\n\u003c\/ul\u003e\n\n\u003ch3\u003eTechnical details\u003c\/h3\u003e\n\u003cul\u003e\n  \u003cli\u003eNodes\/logic used: \u003cb\u003ewebhook\u003c\/b\u003e, \u003cb\u003eif\u003c\/b\u003e, \u003cb\u003ecode\u003c\/b\u003e, \u003cb\u003eswitch\u003c\/b\u003e, \u003cb\u003edata table\u003c\/b\u003e, \u003cb\u003egmail\u003c\/b\u003e.\u003c\/li\u003e\n  \u003cli\u003eCreate and map: \u003cb\u003eKSeF_Lifecycle\u003c\/b\u003e, \u003cb\u003eKSeF_Evidence_Log\u003c\/b\u003e, \u003cb\u003eKSeF_Exception_Queue\u003c\/b\u003e, \u003cb\u003eKSeF_Run_Summaries\u003c\/b\u003e; re-select each table ID in every Data Table node.\u003c\/li\u003e\n  \u003cli\u003eWebhook auth: configure \u003cb\u003eKSEF_INTAKE_TOKEN\u003c\/b\u003e and send it in \u003cb\u003ex-ksef-token\u003c\/b\u003e.\u003c\/li\u003e\n\u003c\/ul\u003e","brand":"N8N Commerce","offers":[{"title":"Default Title","offer_id":45899956093107,"sku":"N8N-18704","price":7.99,"currency_code":"GBP","in_stock":true}],"thumbnail_url":"\/\/cdn.shopify.com\/s\/files\/1\/0749\/6279\/6723\/files\/wVe7XVm3q7EpIyKqAseHN_yz4jIVr9.png?v=1787735490","url":"https:\/\/buyflowscripts.com\/products\/ksef-e-invoice-exception-handling-n8n-webhooks-gmail","provider":"N8N Commerce","version":"1.0","type":"link"}