Zum Hauptinhalt springen
Both endpoints on this page render a finished invoice PDF and store nothing. Use them to show the document in your own create or edit form before the write happens: no invoice, no positions, no file and no activity are created, and the invoice number is not consumed. GET /api/invoices/{id}/preview stays as it is: it renders the draft as it is stored, with no body. Both endpoints need the same permission as the write they preview (invoice:write).

Response

200 OK with the PDF bytes:
The bytes describe an invoice that does not exist yet, so the response must not be cached. In a browser, read it as a blob and hand it to URL.createObjectURL().

Preview a new invoice

The body is the body of POST /api/invoices. customerId is required; everything else is optional and falls back to the customer’s or the environment’s defaults, exactly as it does on create. Positions may be empty, in which case you get the document with no line items.

Preview an update of an existing draft

The body is the body of PUT /api/invoices/{id}, and it is applied to the stored draft in memory only. {id} must be a draft of your own environment; a finalized invoice is refused with the same error PUT /api/invoices/{id} answers with.
Send the FULL payload, not a patch. The preview shows what the write would save, and the write overwrites what it receives:
  • an absent positions key removes every position, so the preview comes back without line items;
  • inside a position, an absent optional field such as description, discountAmount or serviceDateFrom clears it.
Send the same complete payload you would send to PUT /api/invoices/{id}, and the preview matches what you are about to save.
For a payload that equals the stored draft, the answer is the same document GET /api/invoices/{id}/preview returns.

Errors

A 422 carries the same field errors the write answers with, under violations:
Unknown reference IDs are field errors too, so customerId, customerAddressId, paymentMethodId, taxGroupId and currencyCode come back in violations rather than as a late 404.
The preview is the real document, with your letterhead, your document texts and the tax breakdown. Placeholders in title, introduction and closing are resolved, with one exception: an invoice gets its number when it is finalized, so a preview does not print a real invoice number.