Overview
Node.js is the quickest way to get your first KSeF invoice into the Polish e-invoicing system through Notaly. You describe the invoice as plain JSON and send it in one POST request. Notaly generates the FA(3) XML, validates it against the official XSD and submits it to KSeF. This page gives you a complete, runnable example using the global fetch that has shipped with Node.js since version 18, so there is nothing to install.
Before you start
Create a free sandbox account and copy your API key from the dashboard. Two details matter. First, in the sandbox the seller NIP is fixed to 2745013933, the test NIP bound to Notaly's test certificate; a different seller NIP returns 422 seller_nip_not_authorized before the invoice reaches KSeF and before your three free test invoices are used. Second, the Idempotency-Key header makes retries safe: repeating a request with the same key returns the invoice already stored instead of creating a new one. Derive the key from your own invoice identifier and reuse it for every retry of that invoice. A random value generated on each call protects nothing.
Send the invoice
const NOTALY_API_KEY = process.env.NOTALY_API_KEY;
const invoice = {
number: "FV/2026/10/001",
issueDate: "2026-10-12",
currency: "PLN",
seller: { nip: "2745013933", name: "Example Sp. z o.o. (FICTIONAL)", address: { line1: "ul. Testowa 1, 00-001 Warszawa", country: "PL" } },
buyer: { nip: "1234563218", name: "Test Customer S.A. (FICTIONAL)", address: { line1: "ul. Probna 2, 30-001 Kraków", country: "PL" } },
items: [
{ name: "SaaS subscription - October", unit: "pcs.", quantity: 1, unitNetPrice: 1000, vatRate: 23 },
{ name: "Support", unit: "hrs.", quantity: 2, unitNetPrice: 150.5, vatRate: 8 }
]
};
const response = await fetch("https://api.getnotaly.com/invoices", {
method: "POST",
headers: {
Authorization: `Bearer ${NOTALY_API_KEY}`,
"Content-Type": "application/json",
// stable per invoice: reuse the same key when you retry this invoice
"Idempotency-Key": `invoice-${invoice.number}`
},
body: JSON.stringify(invoice)
});
if (!response.ok) {
const body = await response.json();
console.error(`${response.status}:`, body.error, body.details ?? body.message ?? "");
process.exit(1);
}
const created = await response.json();
console.log(`Invoice ${created.id} is ${created.status}`, created.error ?? "");Read the response
A successful call returns HTTP 201 with the invoice object. The most important field is status. It is submitted when KSeF received the invoice and returned a reference number. If the response is draft with error: "ksef_submitting", KSeF has not confirmed the submission yet. Do not send a new POST and do not issue the invoice again under a new number: Notaly resends the same XML automatically. Poll GET /invoices/{id} until the status is submitted. Such a draft already counts towards the three sandbox invoices. If the status is submitted with error: "ksef_duplicate_review", KSeF already has this invoice from an earlier attempt. Do not reissue it with another number; we link it to the KSeF record on our side. If you need it sooner, write to hello@getnotaly.com with the invoice id. If the invoice is draft with error: "ksef_retry_exhausted", Notaly has stopped resending it automatically (after 24 hours, or earlier if KSeF returned a definitive error). Do not create a new invoice: write to hello@getnotaly.com with the invoice id, and we check in KSeF whether it arrived before anything is resent. If an invoice is still draft with error: null or ksef_unavailable after about a minute, Notaly does not resend it: do not create a new invoice; write to hello@getnotaly.com with the invoice id.
The response also carries id (use it to fetch status) and ksefReferenceNumber; once the invoice is accepted, ksefNumber, pdfUrl and, when KSeF issues it, upo. Notaly validates and submits the invoice; VAT rates and tax classification remain your responsibility.
Handle the common errors
Notaly returns structured errors you can branch on. 422 validation_failed includes a details array naming the wrong field. 422 xsd_invalid means the generated FA(3) XML failed the official schema; details lists the elements, and nothing was sent or counted. 422 currency_not_supported means the currency is not PLN, the only currency supported today. 402 quota_exceeded means you have used your three free sandbox invoices. 401 means the API key is missing or invalid and 404 that the resource is not yours. A 503 (ksef_unavailable or validator_unavailable) is transient and nothing was stored; retry with backoff and the same key.
Track the result
const res = await fetch(`https://api.getnotaly.com/invoices/${created.id}`, {
headers: { Authorization: `Bearer ${NOTALY_API_KEY}` }
});
const current = await res.json();
console.log(current.status); // draft | submitted | accepted | rejectedThe lifecycle is draft → submitted → accepted or rejected. You can poll GET /invoices/:id, or subscribe to webhooks so Notaly pushes the final status to your endpoint with a signed header. A rejected invoice carries a stable code such as ksef_rejected:<code>.
Sources
Source: getnotaly.com