# Invoices

Native invoices and their line items, optionally linked to an opportunity or company.

**Base URL:** `https://api.trustpager.com/functions/v1/api/v1`

## Endpoints

### POST /invoices/:invoice_id/line-items

Add one line item to a native invoice. Requires description; line_total and invoice totals are computed.

**Scopes:** `invoices:write` — [full detail](./invoices/post-invoices-invoice-id-line-items.md)

### POST /invoices/:invoice_id/line-items/bulk

Add up to 500 line items to a native invoice in one call. Body: { line_items: [...] }, each item the same shape as add_invoice_line_item. Used for invoice-data imports.

**Scopes:** `invoices:write` — [full detail](./invoices/post-invoices-invoice-id-line-items-bulk.md)

### POST /invoices/bulk

Create up to 100 native invoices in one request, each with inline line_items (header totals computed from the lines). Per-row errors are isolated. Built for high-volume migrations and batch invoicing.

**Scopes:** `invoices:write` — [full detail](./invoices/post-invoices-bulk.md)

### POST /invoices

Create a native invoice, optionally linked to an opportunity and with inline line_items (header totals are computed from the lines). Pass external_order_id to link an ecommerce order.

**Scopes:** `invoices:write` — [full detail](./invoices/post-invoices.md)

### POST /invoices/:invoice_id/payment-link

Generate a Stripe payment link for a native invoice using the workspace's connected Stripe account, and store it on the invoice. The link then appears as the "Pay now" button everywhere the invoice is shown (client portal, invoice emails). Requires Stripe connected under Integrations. One-off charges the outstanding balance; pass recurring_interval (day|week|month|year) to make it a subscription charging the full total each period.

**Scopes:** `invoices:write` — [full detail](./invoices/post-invoices-invoice-id-payment-link.md)

### DELETE /invoices/:invoice_id

Delete a native invoice by UUID (its line items are removed too). Destructive.

**Scopes:** `invoices:write` — [full detail](./invoices/delete-invoices-invoice-id.md)

### DELETE /invoices/:invoice_id/line-items/:line_id

Delete one line item from a native invoice. Invoice totals recompute. Destructive.

**Scopes:** `invoices:write` — [full detail](./invoices/delete-invoices-invoice-id-line-items-line-id.md)

### GET /invoices/:invoice_id

Fetch a single native invoice by UUID, including its line_items.

**Scopes:** `invoices:read` — [full detail](./invoices/get-invoices-invoice-id.md)

### GET /invoices

List native invoices. Filter by opportunity_id, customer_id, status, source_platform, external_order_id, or search invoice number / reference.

**Scopes:** `invoices:read` — [full detail](./invoices/get-invoices.md)

### POST /invoices/:invoice_id/resend

Send an invoice that already exists, again: a branded email with the invoice PDF attached and a "Pay now" link. Unlike send_invoice this also works on invoices held in a connected accounting platform, fetching the current invoice and PDF from it without altering it, so chasing an overdue invoice needs the invoices:write scope rather than a login to the accounting file. Requires the invoice to be approved/open, not draft or voided.

**Scopes:** `invoices:write` — [full detail](./invoices/post-invoices-invoice-id-resend.md)

### POST /invoices/:invoice_id/send

Email a native invoice to its linked contact (or an explicit "to" address) via TrustPager Mail. The email includes the line items, amount due, and a "Pay now" button when the invoice has a payment link (run create_invoice_payment_link first for Stripe card payment); otherwise it shows the workspace bank/BPAY details.

**Scopes:** `invoices:write` — [full detail](./invoices/post-invoices-invoice-id-send.md)

### PATCH /invoices/:invoice_id

Update a native invoice header (status, dates, reference, amount_paid, etc.). amount_due is recomputed. Pass only the fields you want to change.

**Scopes:** `invoices:write` — [full detail](./invoices/patch-invoices-invoice-id.md)

### PATCH /invoices/:invoice_id/line-items/:line_id

Update one line item on a native invoice. line_total and invoice totals recompute when pricing fields change.

**Scopes:** `invoices:write` — [full detail](./invoices/patch-invoices-invoice-id-line-items-line-id.md)
