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
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.
POST
/
db-mgmt
/
api
/
query-ads
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>"
]
}
]
}Required scope:
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
Headers
The API version to use, named by the date it went live (YYYY-MM-DD). Omit it to get
the oldest version that still works. Every response returns the version it used in
the same header. See API versioning.
Example:
"2026-05-26"
Body
application/json
Was this page helpful?