Skip to content

Invoices

Create

Use the standard Create Invoice API for normal invoice creation. It calculates totals and taxes from your line items and applies the regular document lifecycle. The /custom endpoint is only for imports or integrations that must preserve externally calculated totals exactly.

Minimal invoice with inline customer and one line item:

Create minimaltypescript
// title: Minimal invoice
const _invoice = await sdk.invoices.create({
  customer: { name: "Acme Corp" },
  items: [{ name: "Service", quantity: 1, price: 100 }],
});

Or reference saved data:

Create with refstypescript
// title: Invoice with saved references
const _invoice = await sdk.invoices.create({
  customer_id: "cus_abc123",
  items: [
    { item_id: "itm_xyz789", quantity: 5 },
    { name: "Custom service", quantity: 1, price: 250 },
  ],
});

If your rollout needs gross-discount consumer pricing instead of the default B2B flow, see Calculation Modes.

Finalize

Finalize to assign an invoice number and lock the document:

Finalizetypescript
// title: Finalize invoice
// Finalize assigns a document number and locks the invoice
const _finalized = await sdk.invoices.finalize(invoice.id);

Or pass draft: false when creating to finalize immediately.

Download PDF

Render pdftypescript
// title: Render PDF
const pdf = await sdk.invoices.renderPdf(invoice.id);

// Save to file
fs.writeFileSync("invoice.pdf", pdf);

// Or send as response
res.setHeader("Content-Type", "application/pdf");
res.send(pdf);

Send by Email

Send emailtypescript
// title: Send invoice
await sdk.email.send(invoice.id, {
  to: invoice.customer.email,
  subject: "Your invoice #{document_number}",
  body: "Thank you for your business!",
});

Uses the entity’s default email template. See Email API for custom subject/body.

Other Document Types

Same patterns apply to: