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){
"dataset": "ad_metrics",
"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>"
}Analytics SQL
Run a scoped analytics query
Runs one read-only SQL query against a selected Bily dataset. Bily applies the authenticated store scope before the SQL runs.
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){
"dataset": "ad_metrics",
"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
ApiKeyAuthBearerAuth
A server-side Bily API key created under Settings > MCP > Access key fallback. Select the intended store before creating it.
Headers
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
The exact store URL returned by GET /context or GET /stores.
Example:
"store.example.com"
Body
application/json
Available options:
ad_metrics, product_metrics, country_metrics, device_metrics, dimensions, customer_ltv, cohorts, platform_assets, data_quality, datasources_report, touchpoints Read-only SQL that starts with SELECT or WITH and reads from the scoped _ alias.
Maximum string length:
5000Example:
"SELECT channel, sum(spend) AS spend FROM _ GROUP BY channel ORDER BY spend DESC"
Required range:
1 <= x <= 2000Required range:
1 <= x <= 5000Required range:
1 <= x <= 10000Available options:
conversion, first_touch Available options:
day, hour Response
Request completed successfully.
Available options:
ad_metrics, product_metrics, country_metrics, device_metrics, dimensions, customer_ltv, cohorts, platform_assets, data_quality, datasources_report, touchpoints Required range:
x >= 0Show child attributes
Show child attributes
Show child attributes
Show child attributes