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ów21164: 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