KSeF

KSeF codes 21164, 21165, 21178: invoice or UPO not found

Official meaning of KSeF exception codes 21164, 21165 and 21178 when downloading an invoice or a UPO, with the endpoints that return them.

Published 2 min readBy Tomek

Overview

21164, 21165 and 21178 are KSeF API exception codes returned with HTTP 400 when you try to download an invoice or a UPO. In English their official descriptions read: the invoice with the given identifier does not exist (21164), the invoice with the given KSeF number is not yet available (21165), and no UPO was found for the given criteria (21178). All three come from read endpoints, not from sending an invoice.

21164  Faktura o podanym identyfikatorze nie istnieje
21165  Faktura o podanym numerze KSeF nie jest jeszcze dostępna
21178  Nie znaleziono UPO dla podanych kryteriów

21164: the invoice does not exist

Returned by GET /v2/invoices/ksef/{ksefNumber} (download an invoice by KSeF number). The official detail says that the invoice with the given KSeF number was not found:

Faktura o numerze KSeF {ksefNumber} nie została znaleziona.

21165: the invoice is not yet available

Returned by the same endpoint. This is the only code of the three where the specification itself says what to do. Its official detail says that the invoice was processed but is not yet available for download, and that you should try again later:

Faktura o numerze KSeF {ksefNumber} została przetworzona, ale nie jest jeszcze dostępna do pobrania. Spróbuj ponownie później.

21178: UPO not found

Returned by two endpoints: GET /v2/sessions/{referenceNumber}/invoices/ksef/{ksefNumber}/upo (UPO of an invoice from a session, by KSeF number) and GET /v2/sessions/{referenceNumber}/upo/{upoReferenceNumber} (UPO for a session). The official details are templates naming the KSeF number or UPO reference number and the session reference number that were not found.

Where Notaly fits

When you use Notaly you do not call these endpoints yourself. When the invoice status in the session is 200, Notaly stores the KSeF number and requests the UPO from KSeF. When KSeF returns the UPO, both come back in GET /invoices/{id} and in the invoice.accepted webhook, and the dashboard lets you open the UPO of an accepted invoice.

Disclaimer

Notaly is not a tax, accounting or legal advisor. This article is general information, not tax advice, and may be outdated. You are responsible for your own VAT compliance; confirm with a qualified accountant where required.

Sources

Source: api-test.ksef.mf.gov.pl

Frequently asked questions

What is the difference between 21164 and 21165?

21164 says the invoice with the given identifier does not exist; 21165 says the invoice with the given KSeF number is not yet available. Its official detail adds that it was processed but is not yet available for download, and to try again later.

Do I call these endpoints when I use Notaly?

No. Notaly requests the UPO from KSeF when the invoice is accepted and, when KSeF returns it, includes it in the invoice object and the webhook.

Issue your first KSeF test invoice today

Create a sandbox account: API key in seconds, 3 free test invoices on KSeF TEST, no credit card.