The QuickBooks query endpoint: a SQL-like select over one entity.

select * from Invoice where Balance > '0' and TxnDate >= '2026-01-01' orderby TxnDate desc

The language has no joins, no or (use in), and no functions except count(*). String values are single-quoted: build them with literal, which escapes quotes and backslashes, so a customer called O'Brien cannot break (or inject into) the query. Field names are checked with field.

Paging. Pages are STARTPOSITION (1-based) and MAXRESULTS (at most 1000). query fetches one page; query-all follows pages until a short page or limit. Do not put STARTPOSITION or MAXRESULTS in a query passed to query-all.

::q ::quickbooks::query

name "O'Brien Supplies"
vendor first(::q/query(`select * from Vendor where DisplayName = ${::q/literal(name)}`).items)

overdue ::q/query-all(::q/select-from("Invoice", [
  ["Balance", ">", 0],
  ["DueDate", "<", "2026-11-01"]
], "DueDate"), 5000)

open-count ::q/count-rows("Invoice", [["Balance", ">", 0]])

Queries are sent as a POST body (Content-Type: application/text), so long in (...) lists are not limited by URL length.

Values

MAX_PAGES

MAX_PAGES: Int 10000

OPERATORS

OPERATORS: Vec [
  "=",
  "<",
  ">",
  "<=",
  ">=",
  "!=",
  "in",
  "like"
]

Functions

clause

fn (c: Any): Str

One condition for select-from: a [field, op, value] Vec becomes condition(field, op, value); a Str passes through. Anything else is an Err.

Example

::quickbooks::query/clause(["Balance", ">", 0])  // "Balance > '0'"
::quickbooks::query/clause("Active = true")  // "Active = true"

condition

fn (name: Str, op: Str, value: Any): Str

One where condition from a field, an operator (=, <, >, <=, >=, !=, in, like) and a value (escaped with literal). like supports % wildcards inside the value.

::quickbooks::query/condition("DisplayName", "like", "Acme%")   // "DisplayName like 'Acme%'"
::quickbooks::query/condition("Id", "in", ["1", "2"])           // "Id in ('1', '2')"

count-rows

fn (entity: Str, conditions: Vec): Int
fn (entity: Str, conditions: Vec, opts: Map): Int

select count(*) from {entity} where ...: the number of matching rows (totalCount).

Example

open-count ::quickbooks::query/count-rows("Invoice", [["Balance", ">", 0]])
gt(open-count, 0)

entity-of

fn (query: Str): Str?

The entity a query selects from (select * from Invoice where ... gives "Invoice"), or null.

Example

::quickbooks::query/entity-of("select * from Invoice where Balance > '0'")  // "Invoice"
::quickbooks::query/entity-of("not a query")  // null

escape-string

fn (value: Str): Str

Escape a string for a single-quoted query literal: \ becomes \\ and ' becomes \'.

Example

::quickbooks::query/escape-string("O'Brien")  // "O\\'Brien"

field

fn (name: Str): Str

Check a field name (DisplayName, MetaData.LastUpdatedTime, CustomerRef): letters, digits, _ and dots only. Returns it, or an Err.

Example

::quickbooks::query/field("MetaData.LastUpdatedTime")  // "MetaData.LastUpdatedTime"
is-err(::quickbooks::query/field("Id; drop"))  // true

has-paging

fn (query: Str): Bool

True when a query already has STARTPOSITION or MAXRESULTS (case-insensitive).

Example

::quickbooks::query/has-paging("select * from Invoice maxresults 10")  // true
::quickbooks::query/has-paging("select * from Invoice")  // false

literal

fn (value: Any): Str

A query literal for a value: Strs are single-quoted and escaped ("O'Brien" gives 'O\'Brien'); Ints and Decs are written as quoted numbers, which QuickBooks compares numerically; Bools are true / false; a Vec gives an in list ('a', 'b'). Null is an Err.

Example

::quickbooks::query/literal("O'Brien")  // "'O\\'Brien'"
::quickbooks::query/literal(12.5)  // "'12.5'"
::quickbooks::query/literal(true)  // "true"
::quickbooks::query/literal(["a", "b"])  // "('a', 'b')"

next-start

fn (start: Int, size: Int, count: Int): Int?

The STARTPOSITION after a page of count rows fetched from start with page size size, or null when that page was the last (short or empty). Pure.

Example

::quickbooks::query/next-start(1, 100, 100)  // 101
::quickbooks::query/next-start(101, 100, 40)  // null

query

fn (q: Str): Page
fn (q: Str, opts: Map): Page

Run a query and return one Page. Add STARTPOSITION / MAXRESULTS to the query yourself, or use query-page / query-all. Without MAXRESULTS QuickBooks returns at most 100 rows.

Example

page ::quickbooks::query/query("select * from Customer where Active = true MAXRESULTS 50")
map(page.items, %.DisplayName)

::quickbooks::query/query("select * from Vendor", {realm-id: "9341453"})

query-all

fn (q: Str): Vec
fn (q: Str, limit: Int?): Vec
fn (q: Str, limit: Int?, opts: Map): Vec

Run q across pages of 1000 and return every row, or at most limit (null for no limit). The first failing page's Err is returned. Each page is one API call (and, under the Intuit App Partner Program, one metered CorePlus call), so narrow the query with a where clause.

Example

rows ::quickbooks::query/query-all("select * from Invoice where Balance > '0'")
length(rows)

// At most 2500 rows, for one company
::quickbooks::query/query-all("select * from Customer", 2500, {realm-id: "9341453"})

query-page

fn (q: Str, start: Int, max-results: Int): Page
fn (q: Str, start: Int, max-results: Int, opts: Map): Page

Run q for one page from start (1-based) of up to max-results rows (at most 1000).

Example

page ::quickbooks::query/query-page("select * from Invoice orderby TxnDate", 101, 100)
page.start-position
length(page.items)

select-from

fn (entity: Str): Str
fn (entity: Str, conditions: Vec): Str
fn (entity: Str, conditions: Vec, order-by: Str?): Str

Build select * from {entity} [where c1 and c2 ...] [orderby ...]. Each condition is a [field, operator, value] Vec (escaped with condition) or a clause Str you have escaped yourself; order-by is a field optionally followed by asc / desc, or null. Errs on an invalid field, operator, value or orderby.

::quickbooks::query/select-from("Invoice", [["Balance", ">", 0], ["CustomerRef", "=", "58"]], "DueDate")
// "select * from Invoice where Balance > '0' and CustomerRef = '58' orderby DueDate"

to-page

fn (body: Map, entity: Str?): Page

Turn a query response body into a Page (pure). Finds the rows under QueryResponse whatever the key's case.

Example

body {QueryResponse: {Invoice: [{Id: "130"}], startPosition: 1, maxResults: 1}}
page ::quickbooks::query/to-page(body, "Invoice")
page.items  // [{Id: "130"}]
page.max-results  // 1

with-paging

fn (query: Str, start: Int, max-results: Int): Str

Append STARTPOSITION {start} MAXRESULTS {max} to a query (pure). max is clamped to 1..1000.

Example

::quickbooks::query/with-paging("select * from Invoice", 101, 100)
// "select * from Invoice STARTPOSITION 101 MAXRESULTS 100"

Types

Page

Page type {
    items: Vec,
    entity: Str?,
    start-position: Int?,
    max-results: Int?,
    total-count: Int?,
    response: Map
}

One page of query results: items (the entity rows, [] when none), entity, start-position, max-results (rows returned), total-count (from count(*) queries) and the raw response.