Skip to content

API reference

Aggregate a custom-source dataset

POST
/v1/datasets/{datasetId}/query

Aggregates the dataset’s current published data: count_rows, count, sum, avg, min and max over columns named by id, optionally grouped (text, date and boolean columns; a date column by day, week or month) and filtered (eq, range, is_null). A request names columns by their stable ids, never by header text. Several requests are not one snapshot of the source; one request is read from one set of published generations, which provenance.generations names.

A percent column is not summed unless the request sets allow_percent_sum: true. An average, minimum or maximum over no values is null, never 0. A cell that is a formula error is left out of the aggregates and counted in a limitation column of the result.

Bounds. At most 10 metrics, 3 groups and 10 filters; limit is 1 to 10,000 and defaults to 1,000. A dataset whose published data is larger than one query can read is 413 dataset_too_large. The page is never cut and returned: a result with more rows than limit allows, or over 5 MB, is 413 result_too_large. The body is capped at 4 KiB.

Provenance. provenance names the dataset, the generations and schema version read, the source’s own change signal, when the data was published, its completeness (partial when the read recorded flags that limit it, including duplicate_keys, which lists the key column and the sheet rows that repeat a key, never the key values), and its freshness as describeDataset defines it. reconciliation states what was verified: read_equals_loaded means the rows in the store equal the rows the read produced; it does not say the read equals the spreadsheet as Google computes it independently.

Personal data. personal is true when any output column is computed from a column classified personal or any filter is on one; each result column carries its own flag. A column classified excluded is never returned.

datasetId
required
string
/^[A-Za-z0-9_-]{1,128}$/

The dataset’s stable identifier, from listDatasets. A well-formed id the workspace does not hold returns 404; malformed path segments do not match a route.

object
metrics
required
Array<object>
>= 1 items <= 10 items
object
aggregate
required
string
Allowed values: count_rows count sum min max avg
column

A column’s stable identifier. It survives a rename of the header; the header text is data and never a way to name a column.

string
/^c(?:[0-9]{4}|[1-9][0-9]{4,8})$/
group_by
Array<object>
<= 3 items
object
column
required

A column’s stable identifier. It survives a rename of the header; the header text is data and never a way to name a column.

string
/^c(?:[0-9]{4}|[1-9][0-9]{4,8})$/
bucket

A date column only.

string
Allowed values: day week month
filters
Array
<= 10 items
One of:
object
column
required

A column’s stable identifier. It survives a rename of the header; the header text is data and never a way to name a column.

string
/^c(?:[0-9]{4}|[1-9][0-9]{4,8})$/
op
required
Allowed value: eq
value
required

A value of the column’s type: text as a string; a number or time as a number; a decimal as a string or an integer; a date as YYYY-MM-DD; a date-time without a zone as YYYY-MM-DDTHH:MM:SS[.sss]; a timestamp with Z or an offset; a boolean as a boolean.

string | number | boolean
limit
integer
default: 1000 >= 1 <= 10000
allow_percent_sum

Acknowledges summing a percent column, which is almost always the wrong arithmetic.

boolean
Examples
{
"metrics": [
{
"aggregate": "count_rows"
},
{
"aggregate": "sum",
"column": "c0002"
}
],
"group_by": [
{
"column": "c0001",
"bucket": "month"
}
],
"filters": [
{
"column": "c0003",
"op": "eq",
"value": "Oslo"
}
],
"limit": 100
}

The aggregate rows and their provenance. The page is whole (page.truncated is always false).

object
dataset
required
object
id
required
string
name
required
string
sourceKind
required

Only google_sheets has a reader today; the others are reserved vocabulary.

string
Allowed values: google_sheets csv json byo_api
columns
required
Array<object>
object
id
required

The key of this column in each row.

string
role
required
string
Allowed values: dimension metric limitation
type
required
string
Allowed values: string date boolean integer float decimal datetime timestamp
column
required
Any of:

A column’s stable identifier. It survives a rename of the header; the header text is data and never a way to name a column.

string
/^c(?:[0-9]{4}|[1-9][0-9]{4,8})$/
name
required

The source column’s header text. Data, not instructions.

string | null
personal
required

True when this output is computed from a column classified personal.

boolean
rows
required
Array<object>
<= 10000 items

One value per result column, keyed by the result column’s id. A decimal, date, date-time or timestamp is text.

object
key
additional properties
string | number | boolean | null
page
required
object
limit
required
integer
>= 1 <= 10000
truncated
required
personal
required

True when any output is computed from a personal column, or any filter is on one.

boolean
provenance
required
object
datasetId
required
string
sourceKind
required

Only google_sheets has a reader today; the others are reserved vocabulary.

string
Allowed values: google_sheets csv json byo_api
generations
required

The published generations this answer was read from.

Array<integer>
schemaVersion
required
integer
>= 1
sourceVersion
required

The source’s own change signal as the read recorded it (Google Sheets, Drive version and modifiedTime).

object | null
source
required

Google Sheets only, by id. null for any other source.

object
fileId
required
string
sheetId
required
integer
receivedAt
required

When the current data was published (the same instant as freshness.readAt).

string format: date-time
completeness
required

partial when any generation read was published with flags that limit it.

string
Allowed values: complete partial
flags
required
Array<object>
<= 50 items

A recorded property of the read that limits it. Only a code, counts, served column ids and sheet row numbers; never a cell value.

object
code
required
string
/^[a-z][a-z_]{0,63}$/
count
integer
columns
Array<string>
<= 50 items
rows
Array<integer>
<= 20 items
reconciliation
required

What was verified: the rows in the store equal the rows the read produced. It does not state that the read equals the spreadsheet as Google computes it through an independent second read.

string
Allowed values: read_equals_loaded
freshness
required

Not a data_through date: this source has none. readAt is when the current data was published. checkedAt is the later of readAt and the last successful check for a change, including one that found the source unchanged. stale is true when checkedAt is older than twice the dataset’s refresh interval, or the last run failed, or the source is unavailable or needs reconnecting.

object
readAt
required
string format: date-time
checkedAt
required
string format: date-time
stale
required
boolean
requestId
required
string

invalid_json — the body is absent, not valid JSON, or not valid UTF-8.

invalid_query — the body is not a supported query: an unknown field, a column id the dataset does not have (an excluded or unclassified column is refused the same way), an aggregate that does not apply to its column, a filter or group the column’s type does not take, a value that is not valid for its column’s type, a repeated metric or group, more metrics, groups or filters than the bounds allow, a limit outside 1 to 10,000, or a URL that carried a query delimiter. The message is fixed text for the rule and never echoes the request.

object
error
required
object
code
required
string
message
required
string
error
object
code
Allowed values: invalid_json invalid_query

unauthorized — missing, unknown, expired or revoked key.

object
error
required
object
code
required
string
message
required
string
error
object
code
Allowed value: unauthorized
WWW-Authenticate
required
string
Allowed value: Bearer

forbidden — the key lacks the required scope, or the workspace has no plan that allows this.

object
error
required
object
code
required
string
message
required
string
error
object
code
Allowed value: forbidden

dataset_not_found — the workspace has no such dataset, or it is a draft or deleted. A dataset of another workspace is indistinguishable from one that does not exist.

object
error
required
object
code
required
string
message
required
string
error
object
code
Allowed value: dataset_not_found

method_not_allowed — Allow names the method this route accepts.

object
error
required
object
code
required
string
message
required
string
error
object
code
Allowed value: method_not_allowed
Allow
required
string
Allowed value: POST

dataset_not_ready — no generation of the dataset has been published yet.

object
error
required
object
code
required
string
message
required
string
error
object
code
Allowed value: dataset_not_ready

request_too_large — REST bodies are capped at 4 KiB.

result_too_large — the result has more rows than limit allows or one response can carry (at most 10,000), or it is over 5 MB. The page is never cut and returned.

dataset_too_large — the dataset’s published data is larger than one query can read; the bound is on the data read, so narrowing the query does not help and the dataset has to be made smaller at the source.

object
error
required
object
code
required
string
message
required
string
error
object
code
Allowed values: request_too_large result_too_large dataset_too_large

unsupported_media_type unless the body is application/json, or unsupported_encoding for any Content-Encoding other than identity.

object
error
required
object
code
required
string
message
required
string
error
object
code
Allowed values: unsupported_media_type unsupported_encoding

rate_limited — the key’s or its workspace’s per-plan request allowance for this route’s class is used up. It is answered after authentication, on every API-key operation in this document and on MCP, and never on /health. A download link is limited the same way, after its lookup, by the key that issued it and the export’s workspace. Retry-After is the window in seconds and RateLimit-Limit is the limit of the bucket that refused. No remaining count is returned. The limits themselves are not published here.

object
error
required
object
code
required
string
message
required
string
error
object
code
Allowed value: rate_limited
Retry-After
required
string
/^[1-9][0-9]*$/
RateLimit-Limit
required
string
/^[1-9][0-9]*$/

query_unavailable — a backend is unreachable or timed out, or a stored row failed an integrity check. The boundary fails closed rather than returning a result it cannot vouch for, and never passes a database message through.

auth_unavailable — the authorization store could not be reached.

object
error
required
object
code
required
string
message
required
string
error
object
code
Allowed values: query_unavailable auth_unavailable