Query marketing data
query_dataRun an ad-hoc query across one or more connected accounts.
You can skip list_accounts in two cases, both needing connector:
the user NAMES an account —
accounts=["Glamping Tabio"], connector="facebook-ads"resolves it against their authorized accounts. A name matching nothing, or two different accounts, is rejected rather than guessed.the user wants them ALL —
accounts=["*"], connector="facebook-ads"expands to every usable account, so you never type out one id per account.
Otherwise pass the signed accounts refs from list_accounts verbatim (they
bind each account's identity so you never assemble ids by hand), the
metrics and dimensions from list_fields, and a date_range
(a preset like {"preset": "last_30_days"} or explicit
{"from": "2026-01-01", "to": "2026-01-31"}) — pass EITHER a preset OR
explicit bounds, never both. Optional filters is a list of
{"field": <name from list_fields>, "operator": <op>, "value": <value>}
combined with AND, where <op> is one of
eq|neq|gt|gte|lt|lte|contains|ncontains|in|null|notnull.
One side effect worth knowing before you fan out: an account listed as
available (not yet connected) is MATERIALIZED the first time
query_data runs against it, and each materialization takes a licence slot
from the workspace. The read itself changes nothing the caller owns, but
querying a whole listing to see which accounts have data does spend
slots. Query what the user asked about.
Accounts from different connectors are blended into shared columns. Returns
{columns, rows, row_count, truncated}. Read-only. Each row is a
positional tuple aligned with columns, and columns comes back in
the order you asked for (metrics first, then dimensions) — always
read values through columns rather than assuming a layout.
limit is the page size, not a cap on the result. total_rows is the
size of the whole result; when it holds more rows than limit the
response carries a next_cursor. Call again with the SAME arguments
plus cursor=<next_cursor> to read the next page, and repeat until
next_cursor is absent — pages come from the same run, so nothing is
re-extracted and no row is skipped or repeated. Add up every page before
reporting a total. total_rows_is_lower_bound: true means the result is
larger than Porter reads in one query: narrow it (shorter range, fewer
accounts, a filter) instead of paging. A cursor lasts 24 hours.
Presets resolve against the UTC calendar day; last_7_days /
last_30_days end yesterday, while today / this_month /
this_year include the incomplete current day. warnings, when
present, flag ranges that include the not-yet-ingested current day for
storage-backed connectors — surface them to the user instead of
presenting the numbers as final; data_freshness reports
lastRefreshed / coverageUntil of the stored data.
When the user names a connector but no account, do NOT pick one.
Pass every account you have for that connector and add the connector's
account-name dimension (e.g. facebook_ads_account_name). One call
then returns both the figure and WHICH account it belongs to, which is
the question you were about to search for. Trying accounts one at a time
to see which has data costs minutes and answers the same thing.
A query that outlives one tool call comes back as
{"status": "running", "query_id": …} instead of rows. That is NOT an
error and nothing was lost: call get_query_result(query_id=…) with
that id copied verbatim, and call it again immediately if it says running
again. Never re-issue this call to answer a running one — that abandons
the run in flight and starts the extraction over.
coverage says whether the result covers every account you asked for
(complete: true) or some were dropped because the platform denied
access, naming them. Read it and stop: a complete result has nothing
further to find, and re-querying a denied account fails the same way.
Report the gap to the user instead of splitting the query and retrying.
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"accounts": "<accounts>",
"metrics": "<metrics>"
},
"name": "query_data"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| limit | No | ||
| cursor | No | ||
| filters | No | ||
| metrics | Yes | ||
| accounts | Yes | ||
| order_by | No | ||
| connector | No | ||
| date_range | No | ||
| dimensions | No | ||
| compare_date_range | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||