curl --request POST \
--url https://api.upstackdata.com/db-mgmt/api/query-ads \
--header 'Content-Type: application/json' \
--header 'x-api-key: <api-key>' \
--header 'x-pixel-id: <api-key>' \
--data '
{
"pixelId": "5f1e6a4f-...",
"limit": 50
}
'{
"rows": [
{
"basicDetails": {},
"data": {
"primary": [
{
"dt": "<string>",
"start": "<string>",
"end": "<string>"
}
],
"compare": [
{
"dt": "<string>",
"start": "<string>",
"end": "<string>"
}
]
}
}
],
"pagination": {
"limit": 123,
"offset": 123,
"total": 123,
"hasMore": true
}
}{
"message": "<string>",
"errors": [
{
"message": "<string>",
"key": "<string>",
"path": [
"<string>"
]
}
]
}{
"message": "<string>",
"errors": [
{
"message": "<string>",
"key": "<string>",
"path": [
"<string>"
]
}
]
}{
"message": "<string>",
"errors": [
{
"message": "<string>",
"key": "<string>",
"path": [
"<string>"
]
}
]
}{
"message": "<string>",
"errors": [
{
"message": "<string>",
"key": "<string>",
"path": [
"<string>"
]
}
]
}List ads with daily spend and performance metrics
List every ad from your connected Meta, Google, and TikTok accounts as one flat row per ad, with its campaign and ad set, status, and an optional daily spend or performance series.
curl --request POST \
--url https://api.upstackdata.com/db-mgmt/api/query-ads \
--header 'Content-Type: application/json' \
--header 'x-api-key: <api-key>' \
--header 'x-pixel-id: <api-key>' \
--data '
{
"pixelId": "5f1e6a4f-...",
"limit": 50
}
'{
"rows": [
{
"basicDetails": {},
"data": {
"primary": [
{
"dt": "<string>",
"start": "<string>",
"end": "<string>"
}
],
"compare": [
{
"dt": "<string>",
"start": "<string>",
"end": "<string>"
}
]
}
}
],
"pagination": {
"limit": 123,
"offset": 123,
"total": 123,
"hasMore": true
}
}{
"message": "<string>",
"errors": [
{
"message": "<string>",
"key": "<string>",
"path": [
"<string>"
]
}
]
}{
"message": "<string>",
"errors": [
{
"message": "<string>",
"key": "<string>",
"path": [
"<string>"
]
}
]
}{
"message": "<string>",
"errors": [
{
"message": "<string>",
"key": "<string>",
"path": [
"<string>"
]
}
]
}{
"message": "<string>",
"errors": [
{
"message": "<string>",
"key": "<string>",
"path": [
"<string>"
]
}
]
}analytics:read
Use this to pull every ad with its campaign and ad set in one call, export daily
spend per ad, or compare an ad’s last week against the week before. Each row is flat,
so it maps straight onto a spreadsheet or a table in your warehouse.
Listing or metrics
- Leave out
measuresfor a listing: each row has the ad’s IDs, names, andbasicDetails, and nodatakey. - Send
measuresanddateRangetogether to adddata.primary, a daily series per ad.dateRangeis required whenevermeasureshas at least one entry. - Only ad-platform measures work here (
channel.*and per-platform ids such asmeta.spendorgoogle.spend). Any other measure returns400with the unsupported ids. List available measures has the full catalog. - Days with no data for an ad are left out, so an ad that didn’t run in the range
has an empty
data.primaryarray.
Comparison periods
- Send
compareDateRangeto adddata.compare, a daily series for that period. It requiresmeasures, and is rejected with400without them. - Nothing is compared unless you ask. There is no automatic preceding period.
- A
compareDateRangethat overlapsdateRangeis dropped without an error, so the rows only carrydata.primary.
Filtering which ads come back
Every filter field this endpoint accepts narrows the ad list itself, so it also changespagination.total.
| Field | Matches | Operators |
|---|---|---|
channel.resource_source | Platform: facebookIntegration, googleAdsIntegration, tiktokIntegration | equals, not_equals, in, not_in |
channel.account_id, channel.campaign_id, channel.adset_id, channel.ad_id | Platform IDs | equals, in, not_in |
channel.resource_name (the ad’s name), channel.account_name, channel.campaign_name, channel.adset_name, channel.ad_name | Names | equals, not_equals, in, not_in, contains, not_contains, starts_with, ends_with |
channel.resource_status, channel.resource_configured_status, channel.resource_effective_status | Status values such as ACTIVE or PAUSED | equals, not_equals, in, not_in |
orders.*, events.*, and attribution.* fields aren’t accepted here and return
400. To see which UTM campaign or ad gets credit for orders, use
Run an attribution query.
Pagination and sorting
limitis 1 to 500 (default 50) andoffsetskips rows. Keep paging whilepagination.hasMoreistrue.pagination.totalcounts every ad that matchesfilters.- Sort with
sortBy(sourceUpdatedAt,sourceCreatedAt, orresourceName) andsortDirection(ascordesc, lowercase).
Currency
currency (default USD) converts both the daily measures and the budget fields in
basicDetails (dailyBudget, budgetRemaining, amountSpent). Budget fields use the
latest exchange rate. After conversion, basicDetails.currency is the currency you
asked for and basicDetails.nativeCurrency is the ad account’s own currency.
Errors and edge cases
- A filter field this endpoint doesn’t accept returns
400, for exampleFilter field "attribution.utm_campaign" is not valid for context "query_ads". - A measure that fails to compute leaves that measure out of
data, but the request still returns200with the other measures. - A date-only
dateRange.endcovers that whole day. Withtimezoneset, days are read in that zone, otherwise in UTC. pixelIdin the body must equal thex-pixel-idheader, or the request returns403.
Related
upstack query-adsruns the same query from the CLI.- List channel entities for accounts, campaigns, or ad sets instead of ads.
- List filter fields for the fields each endpoint accepts (
query_ads). - List available measures for measure ids.
Authorizations
Your Upstack API key. Starts with upstack_.
The pixel id the request targets.
Body
Must match the x-pixel-id header (403 if it doesn't).
Ad-platform measures to add as a daily series per ad, over dateRange. Leave out for a listing with no metrics.
30Show child attributes
Show child attributes
Required when measures is set. Ignored for a listing.
Show child attributes
Show child attributes
Optional comparison period. Requires measures. Dropped without an error when it overlaps dateRange.
Show child attributes
Show child attributes
Narrows which ads are listed. Only channel.* fields valid for query_ads
are accepted. An or or not group can't mix basic-details and metric
fields.
- All of (and)
- Any of (or)
- Not
Show child attributes
Show child attributes
IANA timezone used to read dateRange and bucket the daily series. Omit for UTC.
"America/New_York"
ISO 4217 code to convert measures and basicDetails budget amounts to
(e.g. EUR). Defaults to USD when omitted. Each row reports the ad
account's own currency in basicDetails.nativeCurrency.
Rows per page.
1 <= x <= 500Rows to skip.
x >= 0Sort key. resourceName is the ad's name.
sourceUpdatedAt, sourceCreatedAt, resourceName Sort direction, lowercase.
asc, desc Was this page helpful?