Configure the KSeF outbound hook for automatic registration of invoices with the Polish e-invoicing system.
The KSeF outbound hook automates the registration of outgoing invoices with the Krajowy System e-Faktur (KSeF), the Polish national e-invoicing system. Invoices are transformed from Peppol BIS Billing 3.0 format to the Polish FA(3) format and registered as a batch. After successful processing, the hook returns the UPO (Urzędowe Poswiadczenie Odbioru, the official acknowledgement of receipt) and a PDF proof via the PSB platform.
The hook supports both an online flow (direct registration) and an offline flow (when KSeF is temporarily unavailable, for example during the daily cutoff). In the offline flow, an offline PDF is generated based on the offline certificate.
After receiving an invoice notification, the hook goes through seven steps:
POST /v2/sessions/batch)GET /v2/sessions/{referenceNumber}/status)When KSeF is unavailable (daily cutoff or outage), the offline flow starts automatically: an offline PDF is generated via the offline certificate, after which the invoice is sent through the regular channel.
Register the hook via the Hooks API:
{
"id": "ksef-sender",
"action": "ksef",
"name": "KSeF Hook Sender",
"topics": [
"ClearInvoiceBatched"
],
"output": [
{
"when": "200",
"topic": "SendInvoice"
},
{
"when": "410",
"topic": "SendInvoice"
}
],
"init": {
"onlineCertificate": "{{path-to-online-certificate}}",
"onlineCertificatePassword": "{{password}}",
"offlineCertificate": "{{path-to-offline-certificate}}",
"offlineCertificatePassword": "{{password}}"
},
"isActive": true
}
onlineCertificateonlineCertificatePasswordofflineCertificateofflineCertificatePasswordtopicsClearInvoiceBatched for outgoing invoicesoutputisActivetrue to activate the hookImportant: All four certificate fields are required. The online certificate is needed for authentication during the online flow. The offline certificate is needed for generating QR codes in the PDF, both during online and offline processing.
200SendInvoice201InvoiceCleared410SendInvoice429InvoiceClearedRetry500InvoiceClearedErrorWith status code 410, the PSB automatically starts the offline flow. The invoice is then processed locally with the offline certificate and sent once KSeF is available again. With 429, the PSB schedules an automatic retry.
KSeF has a daily cutoff period during which the system is unavailable for batch registration. The PSB detects this automatically (status code 410) and switches to the offline flow:
After KSeF returns, invoices processed offline are still registered and the invoice receives status code 201 (InvoiceCleared).
The PSB uses the online certificate to authenticate with KSeF during the online registration flow. The offline certificate is needed for QR codes in the PDF output, both during online and offline processing. All four fields (both certificate paths and passwords) must therefore be filled in.
With 410, KSeF is offline (for example during the cutoff period); the PSB starts the offline flow with an offline PDF and then sends via the regular channel. With 429, there is temporarily no capacity; the PSB automatically schedules a retry on InvoiceClearedRetry.
Use ClearInvoiceBatched in topics so that the hook listens to the correct batch notifications. The output object maps HTTP status codes to follow-up topics such as SendInvoice or InvoiceCleared, depending on the registration result.
Want to learn more about e-invoicing in Poland? Read the country page on the Polish KSeF obligation.
View the API documentation