POST /invoices med en Idempotency-Key, moms som procent, plus listning, storno och markering som betald.
← Tillbaka till API-dokumentationen
Din första faktura i 6 steg
- Skicka POST /v1/invoices med ett buyer-objekt och minst en rad i lines.
- Lägg till headern Idempotency-Key — den krävs, en nyckel per logisk operation.
- Skicka vat_rate som procent (21) och unit_price som NETTO styckpris.
- 201-svaret innehåller id, number, series, summor net/vat/gross och de metadata du skickade.
- Hämta dokumentet med GET /v1/invoices/{id}/pdf eller UBL-XML med GET /v1/invoices/{id}/xml.
Alla endpoints
| Metod | Endpoint | Scope | Idempotency-Key | Förfrågningar / minut |
|---|---|---|---|---|
| POST | /invoices Utfärda en faktura eller proformafaktura | invoices:write | krävs | 30 |
| GET | /invoices Lista fakturor (cursorpaginering) | invoices:read | — | 120 |
| POST | /invoices/preview-totals Beräkna summor utan att skapa något | invoices:read | — | 120 |
| GET | /invoices/{invoice_id} Hämta en faktura | invoices:read | — | 120 |
| GET | /invoices/{invoice_id}/pdf Ladda ned fakturans PDF | invoices:read | — | 120 |
| POST | /invoices/{invoice_id}/storno Utfärda en kreditfaktura som makulerar denna faktura | invoices:write | krävs | 30 |
| POST | /invoices/{invoice_id}/payments Markera fakturan som betald | invoices:write | — | 30 |
| DELETE | /invoices/{invoice_id}/payments Markera fakturan som obetald | invoices:write | — | 30 |
Vad 4invoices API är
bash
curl -sS -X POST https://api.4invoices.net/v1/invoices \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-H 'Content-Type: application/json' \
-H 'Idempotency-Key: order-10457-invoice' \
-d '{
"buyer": {
"name": "Exemplu Comert SRL",
"tax_id": "RO12345678",
"address": "Str. Fabricii 12",
"city": "Cluj-Napoca",
"county": "Cluj",
"country": "RO",
"email": "[email protected]"
},
"lines": [
{ "description": "Abonament SaaS, iulie", "quantity": 1, "unit_price": 400, "vat_rate": 21, "unit": "buc" },
{ "description": "Implementare", "quantity": 6, "unit_price": 250, "vat_rate": 21, "unit": "ora" }
],
"currency": "RON",
"document_kind": "factura",
"due_date": "2026-08-15",
"metadata": { "order_id": "10457" }
}'bash
# Cursorpaginering: följ next_cursor tills has_more är false.
curl -sS "https://api.4invoices.net/v1/invoices?limit=50&status=issued&issued_from=2026-07-01" \
-H "Authorization: Bearer $ACCESS_TOKEN"
# → {"object":"list","data":[...],"has_more":true,"next_cursor":"inv_01J..."}
curl -sS "https://api.4invoices.net/v1/invoices?limit=50&cursor=inv_01J..." \
-H "Authorization: Bearer $ACCESS_TOKEN"bash
curl -sS -X POST https://api.4invoices.net/v1/invoices/inv_01J7ABC/storno \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-H 'Idempotency-Key: storno-inv_01J7ABC-1'
# Kreditfakturan får ett EGET fiskalt nummer; originalets nummer återanvänds aldrig.bash
# Markera som betald
curl -sS -X POST https://api.4invoices.net/v1/invoices/inv_01J7ABC/payments \
-H "Authorization: Bearer $ACCESS_TOKEN"
# Ångra
curl -sS -X DELETE https://api.4invoices.net/v1/invoices/inv_01J7ABC/payments \
-H "Authorization: Bearer $ACCESS_TOKEN"https://api.4invoices.net/v1 · https://api.4invoices.net/v1/openapi.json
Fel
| Status | Typ | Kod |
|---|---|---|
| 422 | invalid_request_error | issuer_profile_incomplete |
| 422 | invalid_request_error | cannot_storno_draft |
| 422 | invalid_request_error | nothing_to_storno |
Vanliga misstag
- Listning är cursorbaserad: följ next_cursor tills has_more är false. Filtren omfattar status, document_kind, buyer_tax_id, issued_from, issued_to och q.
- Ett storno är POST /v1/invoices/{id}/storno och får ett eget fiskalt nummer — originalfakturans nummer återanvänds aldrig.
- En proformafaktura (document_kind proforma) förbrukar inget fiskalt nummer och kan inte lämnas in i det nationella e-fakturasystemet.
- metadata ekas tillbaka vid läsning: lägg in ditt ordernummer där, så behöver du ingen separat mappningstabell.
- POST /v1/invoices/preview-totals kör samma beräkning utan sidoeffekter — praktiskt för att visa summor i din egen varukorg.
Frågor och svar för utvecklare
Hur många rader kan en faktura ha?
Mellan 1 och 400. description är begränsad till 1024 tecken, och quantity måste vara strikt positiv.
Vad händer om jag skickar samma anrop igen efter en timeout?
Med samma Idempotency-Key får du den ursprungliga fakturan plus headern Idempotency-Replayed: true. Inget andra dokument utfärdas.
Hur markerar jag en faktura som betald?
POST /v1/invoices/{id}/payments markerar den som betald, och DELETE på samma sökväg ångrar det. Båda kräver scopet invoices:write.