Invoices API
All endpoints require authentication and invoices tool permissions.
Mapping Rules
Section titled “Mapping Rules”List Mapping Rules
Section titled “List Mapping Rules”GET /api/invoices/mapping-rulesPermission: invoices:view
Response: { rules } — each rule includes service_type_name from joined service_types.
Upsert Mapping Rule
Section titled “Upsert Mapping Rule”PUT /api/invoices/mapping-rules/:serviceTypeIdPermission: invoices:manage
Body:
| Field | Type | Required | Description |
|---|---|---|---|
xero_account_code | string | Yes | Xero account code to map to |
description | string | No | Optional description |
Response: { rule }
Invoices
Section titled “Invoices”List Invoices
Section titled “List Invoices”GET /api/invoicesPermission: invoices:view
Query parameters:
| Param | Type | Description |
|---|---|---|
status | string | Filter by invoice status |
company_id | string | Filter by company |
budget_id | string | Filter by budget |
project_id | string | Filter by project (via budget) |
deal_id | string | Filter by deal (via budget) |
Response: { invoices } — each invoice includes company_name, contact_name, and budget_name.
Create Invoice
Section titled “Create Invoice”POST /api/invoicesPermission: invoices:update
Body:
| Field | Type | Required | Description |
|---|---|---|---|
budget_id | string | No | Link to a budget |
invoice_number | string | No | Custom invoice number (auto-generated if omitted) |
currency | string | No | Currency code (default: AUD) |
due_date | string | No | Due date (YYYY-MM-DD) |
issued_date | string | No | Issue date (defaults to today) |
notes | string | No | Free-text notes |
company_id | string | No | Company ID |
contact_id | string | No | Contact ID |
generate_from_budget | boolean | No | Auto-generate line items from budget |
When generate_from_budget is true, line item generation depends on the budget type:
- Sprints / Retainer: copies budget line items at their fixed amounts. Retainer budgets can only be invoiced once.
- Time & Materials: invoices only approved, uninvoiced time per line item.
- Fixed Price: invoices the remaining uninvoiced amount as a single line item.
Tax is calculated at 10% GST. Auto-completes client onboarding milestone first_invoice for the company’s first invoice.
Response: { invoice } (201)
Get Invoice Detail
Section titled “Get Invoice Detail”GET /api/invoices/:idPermission: invoices:view
Response: { invoice, line_items, payments }
The invoice includes company_name, contact_name, budget_name, project_name, project_id, po_number, xero_status, and xero_url. If linked to Xero, the status is synced live from Xero on each request.
Update Invoice
Section titled “Update Invoice”PUT /api/invoices/:idPermission: invoices:update
Body: Any of the following fields:
| Field | Type | Description |
|---|---|---|
invoice_number | string | Invoice number |
status | string | Invoice status |
currency | string | Currency code |
due_date | string | Due date |
issued_date | string | Issue date |
notes | string | Notes |
company_id | string | Company ID |
contact_id | string | Contact ID |
budget_id | string | Budget ID |
xero_invoice_id | string | Xero invoice ID |
Response: { invoice }
Delete Invoice
Section titled “Delete Invoice”DELETE /api/invoices/:idPermission: invoices:manage
If linked to Xero, the invoice is deleted (if DRAFT) or voided (if AUTHORISED+) in Xero before local deletion.
Response: { ok: true }
Xero Integration
Section titled “Xero Integration”Push to Xero
Section titled “Push to Xero”POST /api/invoices/:id/push-to-xeroPermission: invoices:update
Creates a DRAFT invoice in Xero from the local invoice and line items. Uses the company name as the Xero contact, and maps line item account codes from mapping rules. Sets local status to finalised.
Response: { invoice, xero_invoice_id }
Approve in Xero
Section titled “Approve in Xero”POST /api/invoices/:id/xero-approvePermission: invoices:manage
Transitions a Xero DRAFT invoice to AUTHORISED. Sets local status to approved.
Response: { invoice }
Send via Xero
Section titled “Send via Xero”POST /api/invoices/:id/xero-sendPermission: invoices:manage
Sends an AUTHORISED Xero invoice via email. Sets local status to sent.
Response: { invoice }
Void in Xero
Section titled “Void in Xero”POST /api/invoices/:id/xero-voidPermission: invoices:manage
Voids the Xero invoice. Sets local status to voided.
Response: { invoice }
Delete from Xero
Section titled “Delete from Xero”POST /api/invoices/:id/xero-deletePermission: invoices:manage
Deletes the Xero invoice (DRAFT only). Clears the local Xero ID and resets status to draft.
Response: { invoice }
Download PDF from Xero
Section titled “Download PDF from Xero”GET /api/invoices/:id/pdfPermission: invoices:view
Downloads the invoice PDF from Xero. Returns application/pdf with Content-Disposition: attachment.
Sync All from Xero
Section titled “Sync All from Xero”POST /api/invoices/sync-xeroPermission: invoices:update
Batch syncs payment status, amounts paid/due, and individual payments for all Xero-linked invoices.
Response: { updated, errors, synced_at }
Sync Single from Xero
Section titled “Sync Single from Xero”POST /api/invoices/:id/sync-xeroPermission: invoices:update
Syncs payment status and payments for a single Xero-linked invoice.
Response: { invoice, payments, xero_status, payment_status }
Line Items
Section titled “Line Items”Reorder Line Items
Section titled “Reorder Line Items”PUT /api/invoices/:id/line-items/reorderPermission: invoices:update
Body:
| Field | Type | Required | Description |
|---|---|---|---|
item_ids | string[] | Yes | Ordered array of line item IDs |
Response: { ok: true }
Add Line Item
Section titled “Add Line Item”POST /api/invoices/:id/line-itemsPermission: invoices:update
Body:
| Field | Type | Required | Description |
|---|---|---|---|
description | string | Yes | Line item description |
quantity | number | No | Quantity (default: 1) |
unit_price | number | No | Unit price (default: 0) |
service_type_id | string | No | Service type ID |
xero_account_code | string | No | Xero account code |
tax_type | string | No | Tax type |
position | number | No | Sort position |
Automatically recalculates invoice totals (subtotal, 10% GST, total).
Response: { item } (201)
Update Line Item
Section titled “Update Line Item”PUT /api/invoices/:id/line-items/:itemIdPermission: invoices:update
Body: Any of: description, quantity, unit_price, service_type_id, xero_account_code, tax_type, position.
Automatically recalculates line item amount and invoice totals.
Response: { item }
Delete Line Item
Section titled “Delete Line Item”DELETE /api/invoices/:id/line-items/:itemIdPermission: invoices:update
Automatically recalculates invoice totals.
Response: { ok: true }