Skip to main content
POST
/
ad-metrics
/
{storeUrl}
/
query
Run a scoped analytics query
curl --request POST \
  --url https://app.bily.ai/api/customer/v1/ad-metrics/{storeUrl}/query \
  --header 'Content-Type: application/json' \
  --header 'x-api-key: <api-key>' \
  --data '
{
  "sql": "SELECT channel, sum(spend) AS spend FROM _ GROUP BY channel ORDER BY spend DESC"
}
'
const options = {
method: 'POST',
headers: {'x-api-key': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
sql: 'SELECT channel, sum(spend) AS spend FROM _ GROUP BY channel ORDER BY spend DESC'
})
};

fetch('https://app.bily.ai/api/customer/v1/ad-metrics/{storeUrl}/query', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));
import requests

url = "https://app.bily.ai/api/customer/v1/ad-metrics/{storeUrl}/query"

payload = { "sql": "SELECT channel, sum(spend) AS spend FROM _ GROUP BY channel ORDER BY spend DESC" }
headers = {
"x-api-key": "<api-key>",
"Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.text)
{
  "storeUrl": "<string>",
  "maxRows": 123,
  "inputLimit": 123,
  "page": 123,
  "adAccountScope": 1,
  "meta": [
    {
      "name": "<string>",
      "type": "<string>"
    }
  ],
  "data": [
    {}
  ],
  "rows": 123,
  "statistics": {
    "elapsed": 123,
    "rows_read": 123,
    "bytes_read": 123
  }
}
{
"error": "Store not found",
"requestId": "<string>",
"details": "<unknown>",
"retryAfter": "<string>"
}
{
"error": "Store not found",
"requestId": "<string>",
"details": "<unknown>",
"retryAfter": "<string>"
}
{
"error": "Store not found",
"requestId": "<string>",
"details": "<unknown>",
"retryAfter": "<string>"
}
{
"error": "Store not found",
"requestId": "<string>",
"details": "<unknown>",
"retryAfter": "<string>"
}
{
"error": "Store not found",
"requestId": "<string>",
"details": "<unknown>",
"retryAfter": "<string>"
}

Authorizations

x-api-key
string
header
required

A server-side Bily API key created under Settings > MCP > Access key fallback. Select the intended store before creating it.

Headers

x-bily-organization-id
string

An organization ID returned by GET /context or GET /organizations. Required for GET /stores and optional for store-scoped paths.

Example:

"org_01J8W7T9G3E6ZQ4M2K5N8P1R0S"

Path Parameters

storeUrl
string
required

The exact store URL returned by GET /context or GET /stores.

Example:

"store.example.com"

Body

application/json
dataset
enum<string>
required
Available options:
ad_metrics,
product_metrics,
country_metrics,
device_metrics,
dimensions,
customer_ltv,
cohorts,
platform_assets,
data_quality,
datasources_report,
touchpoints
sql
string
required

Read-only SQL that starts with SELECT or WITH and reads from the scoped _ alias.

Maximum string length: 5000
Example:

"SELECT channel, sum(spend) AS spend FROM _ GROUP BY channel ORDER BY spend DESC"

maxRows
integer
default:250
Required range: 1 <= x <= 2000
inputLimit
integer
default:1000
Required range: 1 <= x <= 5000
page
integer
default:1
Required range: 1 <= x <= 10000
startDate
string<date>
endDate
string<date>
channel
string
adId
string
productId
country
deviceType
os
browser
dimensionSource
enum<string>
Available options:
conversion,
first_touch
granularity
enum<string>
Available options:
day,
hour
includeOS
boolean
includeBrowser
boolean
bilyId
string

Response

Request completed successfully.

dataset
enum<string>
required
Available options:
ad_metrics,
product_metrics,
country_metrics,
device_metrics,
dimensions,
customer_ltv,
cohorts,
platform_assets,
data_quality,
datasources_report,
touchpoints
storeUrl
string
required
maxRows
integer
required
inputLimit
integer
required
page
integer
required
adAccountScope
integer
required
Required range: x >= 0
meta
object[]
required
data
object[]
required
rows
integer
required
statistics
object | null
required