Invoices
Create
Minimal invoice with inline customer and one line item:
// title: Minimal invoice
const invoice = await sdk.invoices.create({
customer: { name: "Acme Corp" },
items: [{ name: "Service", quantity: 1, price: 100 }],
});Or reference saved data:
// 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 },
],
});Finalize
Finalize to assign an invoice number and lock the document:
// title: Finalize invoice
// Finalize assigns a document number and locks the invoice
const finalized = await sdk.invoices.finalize(invoice.id);
console.log(finalized.number); // __PROTECTED_0__
console.log(finalized.status); // __PROTECTED_1__Or pass draft: false when creating to finalize immediately.
Download PDF
// 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
// 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:
- Estimates — Quotes
- Credit Notes — Refunds
- Advance Invoices — Prepayments