Skip to main content

HTTP API reference

Invoices & chart data

List and edit saved rows. `GET /api/invoices/aggregates` returns monthly series or top counterparties for dashboards — not the same as `GET /api/bi/summary` (period P&L totals).

Endpoints in this topic

GET/api/invoices

Paginated list of stored invoices for the authenticated user.

Request
GET — query: page (≥1, default 1), limit (1–200, default 20), kind=expense|revenue, from / to (YYYY-MM-DD on parsed document date), q (search, max 200 chars; counterparty / invoice # / raw text).
Response
{
  invoices[], page, limit, total, totalPages
}

Each invoice: id, createdAt, invoiceKind, provider,
  invoiceNumber, documentDate, total, currency, fileUrl, mimeType.

GET/api/invoices/[id]

Fetch one invoice by id (path param).

Request
Path segment [id] = invoice UUID.
Response
{
  invoice: {
    id, createdAt, invoiceKind, provider, invoiceNumber,
    documentDate, total, currency, fileUrl, mimeType, rawText?
  }
}

PATCH/api/invoices/[id]

Update invoice_kind and/or parsed_data fields.

Request
Content-Type: application/json

{
  "invoice_kind": "expense" | "revenue",
  "parsed_data": { partial InvoiceExtract }
}
(both fields optional; parsed_data merges into existing parsed_data then re-validates)
Response
{
  invoice: { …same shape as GET /api/invoices/[id] … }
}

DELETE/api/invoices/[id]

Delete a stored invoice.

Request
Path segment [id] = invoice UUID.
Response
200 { ok: true }. 404 with error JSON if the row is missing.

GET/api/invoices/aggregates

Monthly revenue/expense series or top counterparties (groupBy=month|counterparty). Respects reporting currency like GET /api/bi/summary; response includes `caveats`.

Request
GET — query: from, to (YYYY-MM-DD; default ≈ last 365 days UTC), groupBy=month | counterparty, kind=expense|revenue (counterparty mode only; default revenue), limit (1–50, default 10 for counterparty top-N).
Response
groupBy=month: {
  groupBy, period, series: [{ period, revenue, expenses }], caveats
}

groupBy=counterparty: {
  groupBy, kind, period,
  counterparties: [{ name, kind, total, invoiceCount }], caveats
}
Invoices & chart data — API reference · BillflowAI