GET /api/agent/invoices
Returns AR invoices (CashItem source = XERO_INVOICE) for the caller's org. Filterable by Xero status, contact, and date range. Two pagination modes: (1) cursor pagination via cursor / nextCursor (default, max 200 rows per page — caller MUST loop until nextCursor is null), or (2) ?autoPaginate=true opt-in which loops pages server-side and returns the combined set in one response (hard-capped at 5,000 rows; truncated: true is set when the cap is hit so the caller knows to fall back to cursor mode). For sum/total calculations always use ?autoPaginate=true or loop the cursor to completion — reporting partial-page sums as totals is the most common agentic failure mode this endpoint guards against. The response always includes totalCount (pre-redaction match count) so agents can decide up-front whether to paginate. Opt-in totals (?totals=true): when set, the response carries an aggregate totals.byStatus + totals.grandTotal block computed across the full filtered set (not just the page); prefer this over ?autoPaginate=true for pure aggregate questions ("how much have I invoiced YTD?") as it avoids transporting the rows. Chasing a customer? Read amountDue, and read amountPaid for what has come in. On an OPEN invoice amount usually carries the same number as amountDue — it is not a separate face value — so chasing on amount is not normally wrong by the balance, but amountDue is still the field to read: it reports null where amount reports 0 when Xero gave us no balance (unknown vs settled — never conflate them), and it means the same thing on every row, whereas amount does not. amount is not a gross-invoiced figure and must not be reported as one, even across rows of a single status — on an open invoice it is the outstanding balance, and a settled one is usually but NOT reliably rewritten to the gross total. Note this applies to ?totals=true as well, which aggregates the same field; it is not a workaround. If you are asked what was invoiced or billed rather than what is owed, say that the figure available here is balance-based and name the caveat. To find out whether a credit note reduced an invoice, ask — do not infer. Set credits=true and read creditedAmount; that is the only reliable signal. Arithmetic over these three fields does NOT work on an open invoice: because amount and amountDue hold the same figure there, amount - amountDue - amountPaid is 0 on a partially-credited invoice (it misses the credit entirely) and NEGATIVE on a part-paid one (it claims a credit that does not exist). On a PAID invoice, amountDue: "0" together with amountPaid: "0" is a reasonable hint that a credit note rather than cash closed it — confirm with credits=true before reporting it. Set lines=true to include each invoice's XeroInvoiceLine[]. Line items carry per-unit pricing (quantity, unitAmount) plus line-level discount data (discountRate 0–1, discountAmount, lineSubtotal) so callers can reconcile lineSubtotal * (1 - discountRate) ≈ lineAmount without going back to Xero. Sensitive contacts and (when lines=true) sensitive account codes drop invoices from the response unless the key carries READ_SENSITIVE; the redactedItemCount field surfaces the count of dropped rows. This endpoint EXCLUDES credit notes (CN-####) — they are a separate Xero document type. Use /api/agent/credit-notes (and /api/agent/credit-notes/{id}) to look those up. A 'not found' here does NOT mean a claimed credit doesn't exist; check the credit-note endpoint before concluding a credit is absent.
Auth
- Required scope:
READ_INVOICES - Header:
Authorization: Bearer cr_live_<prefix>_<secret>
Query parameters
| Name | Type | Required | Notes |
|---|---|---|---|
status | string | no | Comma-separated list of Xero invoice statuses: DRAFT, SUBMITTED, AUTHORISED, PAID, VOIDED, DELETED. Unknown values are ignored. VOIDED and DELETED behave differently from every other value in this enum: voided documents are EXCLUDED BY DEFAULT and appear only when you name VOIDED or DELETED here explicitly. Omitting status therefore returns live documents only, and totalCount / totals describe that same live set. CAVEAT — as a FILTER, VOIDED and DELETED are aliases: both select every tombstoned document, because the stored status collapses the two. Discriminate on the returned xeroStatus (and voidedAt) per row instead. The totals.byStatus breakdown reports all tombstones under the VOIDED bucket for the same reason. |
contactId | string | no | Filter by Xero contact external id. |
dateFrom | string | no | Inclusive lower bound on the issue date (issueDate, falling back to the due date when the issue date is unknown) (YYYY-MM-DD). |
dateTo | string | no | Inclusive upper bound on the issue date (issueDate, falling back to the due date when the issue date is unknown) (YYYY-MM-DD; expanded to end-of-day UTC). |
sent | boolean | no | Filter by send status. false returns only invoices Xero records as never sent — combine with status=AUTHORISED to find invoices raised but never delivered. true returns only sent (or marked-sent) invoices. Matching is EXACT: records with an unknown send status (sent: null, i.e. not yet re-synced) are excluded by BOTH values, so sent=false never misreports an unchecked record as unsent. Omit the parameter to include every invoice regardless of send status. Unrecognised values are ignored rather than rejected. totalCount and totals narrow with this filter. |
cursor | string | no | Opaque cursor returned by a prior request's nextCursor. |
limit | integer | no | Max rows per page. Capped at 200. |
lines | boolean | no | When true, include XeroInvoiceLine[] per invoice. |
credits | boolean | no | When true, add creditedAmount and creditNotes[] to every returned invoice — the credit notes applied to it and how much each contributed. Prefer this over searching /api/agent/credit-notes when you already hold the invoice: it answers "was this invoice credited down?" in one call. Both keys are ABSENT when this flag is off, so their null never means "you didn't ask". Does NOT change which invoices are returned, nor totalCount / totals. |
autoPaginate | boolean | no | When true, the server loops pages internally and returns the combined matched set in one response (hard-capped at 5,000; truncated: true is set on overflow). Mutually exclusive with cursor — cursor is silently ignored when autoPaginate=true. Use this for sum / aggregate reads to avoid partial-page-totalling bugs. |
totals | boolean | no | When true, the response carries an aggregate totals block computed across the FULL filtered set (NOT just the page). Shape: { byStatus: { PAID: { count, amount }, AUTHORISED: {...}, ... }, grandTotal: { count, amount }, currency }. Mixed-currency sets short-circuit to { mixedCurrency: true, primaryCurrency, byStatus: null }. Over the 100K aggregation cap, totals is omitted and totalsTruncated: true is set instead. Off by default — the aggregation runs an extra GROUP BY status, SUM(amount) query so reserve it for the questions that need it. |
Responses
200 — Page of invoices
Body: InvoicesResponse
| Field | Type | Required | Notes |
|---|---|---|---|
invoices | array of Invoice | yes | |
nextCursor | string | yes | Opaque base64url cursor — pass back as ?cursor=... on the next request. Always present; null signals 'this is the last page in this view'. Both the natural last page AND an ?autoPaginate=true response (truncated or not) emit null — truncation is signalled via the separate truncated field, not via the cursor. |
totalCount | integer | yes | Total number of rows matching the request filters (pre-redaction). Reconciles to Xero source-of-truth; the page array may be shorter if sensitive rows were dropped (the delta is redactedItemCount). Always present. |
redactedItemCount | integer | yes | Number of rows withheld in this page due to sensitive-data gating. Always 0 when the key carries READ_SENSITIVE. |
truncated | boolean | no | Present and true only when ?autoPaginate=true was requested and more than 5,000 rows matched. The response carries the first 5,000 rows; fall back to cursor pagination (drop autoPaginate=true) to read the rest. Absent on healthy responses. |
totals | InvoiceBillTotals | no | |
totalsTruncated | boolean | no | Present and true only when ?totals=true was requested AND the matched set exceeded the 100,000-row aggregation cap. The totals block is omitted in this case; refine the filter (date range / status) to bring the scan back under the cap. |
billingAlert | BillingAlert | no | |
xeroAlert | XeroAlert | no |
401 — Unauthorized
Body: ErrorResponse
| Field | Type | Required | Notes |
|---|---|---|---|
error | string | yes |
403 — Key lacks the required scope
Body: ErrorResponse
| Field | Type | Required | Notes |
|---|---|---|---|
error | string | yes |
429 — Rate-limited (per-minute burst) or query credits exhausted. Credits return individually on a rolling 5h window — retry after Retry-After seconds for one more call.
Body:
any
Response headers
Every successful response carries X-CashRunway-Subscription, X-CashRunway-Plan, X-CashRunway-Quota-Remaining, and X-CashRunway-Quota-Reset. Trialing subscriptions also include X-CashRunway-Trial-Days-Remaining. See the overview for details.