curl --request POST \
--url https://api.datalyr.com/v1/query \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"metrics": [
"spend",
"provider_roas"
],
"dimensions": [
"campaign"
],
"filters": [
{
"dimension": "platform",
"op": "eq",
"value": "meta"
}
],
"date_range": {
"preset": "last_30_days"
},
"order_by": [
{
"field": "spend",
"dir": "desc"
}
],
"limit": 20
}
'import requests
url = "https://api.datalyr.com/v1/query"
payload = {
"metrics": ["spend", "provider_roas"],
"dimensions": ["campaign"],
"filters": [
{
"dimension": "platform",
"op": "eq",
"value": "meta"
}
],
"date_range": { "preset": "last_30_days" },
"order_by": [
{
"field": "spend",
"dir": "desc"
}
],
"limit": 20
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
metrics: ['spend', 'provider_roas'],
dimensions: ['campaign'],
filters: [{dimension: 'platform', op: 'eq', value: 'meta'}],
date_range: {preset: 'last_30_days'},
order_by: [{field: 'spend', dir: 'desc'}],
limit: 20
})
};
fetch('https://api.datalyr.com/v1/query', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.datalyr.com/v1/query",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'metrics' => [
'spend',
'provider_roas'
],
'dimensions' => [
'campaign'
],
'filters' => [
[
'dimension' => 'platform',
'op' => 'eq',
'value' => 'meta'
]
],
'date_range' => [
'preset' => 'last_30_days'
],
'order_by' => [
[
'field' => 'spend',
'dir' => 'desc'
]
],
'limit' => 20
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.datalyr.com/v1/query"
payload := strings.NewReader("{\n \"metrics\": [\n \"spend\",\n \"provider_roas\"\n ],\n \"dimensions\": [\n \"campaign\"\n ],\n \"filters\": [\n {\n \"dimension\": \"platform\",\n \"op\": \"eq\",\n \"value\": \"meta\"\n }\n ],\n \"date_range\": {\n \"preset\": \"last_30_days\"\n },\n \"order_by\": [\n {\n \"field\": \"spend\",\n \"dir\": \"desc\"\n }\n ],\n \"limit\": 20\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.datalyr.com/v1/query")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"metrics\": [\n \"spend\",\n \"provider_roas\"\n ],\n \"dimensions\": [\n \"campaign\"\n ],\n \"filters\": [\n {\n \"dimension\": \"platform\",\n \"op\": \"eq\",\n \"value\": \"meta\"\n }\n ],\n \"date_range\": {\n \"preset\": \"last_30_days\"\n },\n \"order_by\": [\n {\n \"field\": \"spend\",\n \"dir\": \"desc\"\n }\n ],\n \"limit\": 20\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.datalyr.com/v1/query")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"metrics\": [\n \"spend\",\n \"provider_roas\"\n ],\n \"dimensions\": [\n \"campaign\"\n ],\n \"filters\": [\n {\n \"dimension\": \"platform\",\n \"op\": \"eq\",\n \"value\": \"meta\"\n }\n ],\n \"date_range\": {\n \"preset\": \"last_30_days\"\n },\n \"order_by\": [\n {\n \"field\": \"spend\",\n \"dir\": \"desc\"\n }\n ],\n \"limit\": 20\n}"
response = http.request(request)
puts response.read_body{
"rows": [
{}
],
"totals": {},
"meta": {
"resolved": {
"metrics": [
{
"id": "<string>",
"label": "<string>",
"unit": "count",
"definition": "<string>",
"domain": "events",
"attributed": true,
"currency": "<string>"
}
],
"dimensions": [
{}
],
"filters": [
{
"dimension": "<string>",
"op": "eq",
"value": "<string>"
}
],
"date_range": {
"from": "<string>",
"to": "<string>",
"timezone": "<string>",
"preset": "<string>"
},
"granularity": "<string>",
"attribution": {
"model": "<string>",
"window_days": 123,
"source": "requested"
}
},
"returned_rows": 123,
"truncated": true,
"total_rows": 123,
"next_cursor": "<string>",
"freshness": [
{
"source": "<string>",
"latest_at": "<string>"
}
],
"unavailable": [
{
"metric": "<string>",
"reason": "<string>",
"detail": "<string>"
}
],
"deep_link": "<string>",
"executed_in_ms": 123,
"notes": [
"<string>"
]
},
"comparison": {
"date_range": {
"from": "<string>",
"to": "<string>"
},
"totals": {},
"rows": [
{}
]
},
"data_notice": "<string>"
}{
"error": "<string>",
"code": "unknown_metric",
"hint": "<string>"
}{
"error": "<string>"
}{
"error": "<string>"
}{
"error": "<string>"
}Run a query plan
Any metric by any dimension, filter and time range. Get metric ids from GET /search?kind=metric and dimension ids from GET /dimensions. Funnels, retention, cohort LTV and one person’s journey have their own routes.
A plan the server cannot run is a 400 with error, code and a hint that says how to fix it. The body is capped at 64 KiB (413 above it). A query runs for at most 20 seconds; a source that did not answer in time is listed in meta.unavailable with reason timeout.
curl --request POST \
--url https://api.datalyr.com/v1/query \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"metrics": [
"spend",
"provider_roas"
],
"dimensions": [
"campaign"
],
"filters": [
{
"dimension": "platform",
"op": "eq",
"value": "meta"
}
],
"date_range": {
"preset": "last_30_days"
},
"order_by": [
{
"field": "spend",
"dir": "desc"
}
],
"limit": 20
}
'import requests
url = "https://api.datalyr.com/v1/query"
payload = {
"metrics": ["spend", "provider_roas"],
"dimensions": ["campaign"],
"filters": [
{
"dimension": "platform",
"op": "eq",
"value": "meta"
}
],
"date_range": { "preset": "last_30_days" },
"order_by": [
{
"field": "spend",
"dir": "desc"
}
],
"limit": 20
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
metrics: ['spend', 'provider_roas'],
dimensions: ['campaign'],
filters: [{dimension: 'platform', op: 'eq', value: 'meta'}],
date_range: {preset: 'last_30_days'},
order_by: [{field: 'spend', dir: 'desc'}],
limit: 20
})
};
fetch('https://api.datalyr.com/v1/query', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.datalyr.com/v1/query",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'metrics' => [
'spend',
'provider_roas'
],
'dimensions' => [
'campaign'
],
'filters' => [
[
'dimension' => 'platform',
'op' => 'eq',
'value' => 'meta'
]
],
'date_range' => [
'preset' => 'last_30_days'
],
'order_by' => [
[
'field' => 'spend',
'dir' => 'desc'
]
],
'limit' => 20
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.datalyr.com/v1/query"
payload := strings.NewReader("{\n \"metrics\": [\n \"spend\",\n \"provider_roas\"\n ],\n \"dimensions\": [\n \"campaign\"\n ],\n \"filters\": [\n {\n \"dimension\": \"platform\",\n \"op\": \"eq\",\n \"value\": \"meta\"\n }\n ],\n \"date_range\": {\n \"preset\": \"last_30_days\"\n },\n \"order_by\": [\n {\n \"field\": \"spend\",\n \"dir\": \"desc\"\n }\n ],\n \"limit\": 20\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.datalyr.com/v1/query")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"metrics\": [\n \"spend\",\n \"provider_roas\"\n ],\n \"dimensions\": [\n \"campaign\"\n ],\n \"filters\": [\n {\n \"dimension\": \"platform\",\n \"op\": \"eq\",\n \"value\": \"meta\"\n }\n ],\n \"date_range\": {\n \"preset\": \"last_30_days\"\n },\n \"order_by\": [\n {\n \"field\": \"spend\",\n \"dir\": \"desc\"\n }\n ],\n \"limit\": 20\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.datalyr.com/v1/query")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"metrics\": [\n \"spend\",\n \"provider_roas\"\n ],\n \"dimensions\": [\n \"campaign\"\n ],\n \"filters\": [\n {\n \"dimension\": \"platform\",\n \"op\": \"eq\",\n \"value\": \"meta\"\n }\n ],\n \"date_range\": {\n \"preset\": \"last_30_days\"\n },\n \"order_by\": [\n {\n \"field\": \"spend\",\n \"dir\": \"desc\"\n }\n ],\n \"limit\": 20\n}"
response = http.request(request)
puts response.read_body{
"rows": [
{}
],
"totals": {},
"meta": {
"resolved": {
"metrics": [
{
"id": "<string>",
"label": "<string>",
"unit": "count",
"definition": "<string>",
"domain": "events",
"attributed": true,
"currency": "<string>"
}
],
"dimensions": [
{}
],
"filters": [
{
"dimension": "<string>",
"op": "eq",
"value": "<string>"
}
],
"date_range": {
"from": "<string>",
"to": "<string>",
"timezone": "<string>",
"preset": "<string>"
},
"granularity": "<string>",
"attribution": {
"model": "<string>",
"window_days": 123,
"source": "requested"
}
},
"returned_rows": 123,
"truncated": true,
"total_rows": 123,
"next_cursor": "<string>",
"freshness": [
{
"source": "<string>",
"latest_at": "<string>"
}
],
"unavailable": [
{
"metric": "<string>",
"reason": "<string>",
"detail": "<string>"
}
],
"deep_link": "<string>",
"executed_in_ms": 123,
"notes": [
"<string>"
]
},
"comparison": {
"date_range": {
"from": "<string>",
"to": "<string>"
},
"totals": {},
"rows": [
{}
]
},
"data_notice": "<string>"
}{
"error": "<string>",
"code": "unknown_metric",
"hint": "<string>"
}{
"error": "<string>"
}{
"error": "<string>"
}{
"error": "<string>"
}Authorizations
Bearer authentication header of the form Bearer <token>, where <token> is your auth token.
Body
Measure ids, such as visitors, revenue, spend, provider_roas, attributed_revenue, active_subscriptions, or custom:<event_name>.
1 - 10 elements{from, to} (inclusive; YYYY-MM-DD in the workspace timezone, or ISO 8601 instants) or {preset}.
- Option 1
- Option 2
Show child attributes
Show child attributes
Dimension ids from GET /dimensions. Omit for totals only.
3Combined with AND.
20Show child attributes
Show child attributes
Adds a bucket column. Omit for one row per dimension combination.
hour, day, week, month, null Also compute the preceding window of equal width.
previous_period, null Required for attributed_* metrics; the workspace default applies when omitted. Echoed in meta.resolved.attribution.
Show child attributes
Show child attributes
3Show child attributes
Show child attributes
1 <= x <= 2000meta.next_cursor from the previous page.
concise, detailed Response
Successful response. Shape evolving — read fields defensively and do not depend on the absence of a field.
One object per dimension combination (and bucket). Keys are dimension ids, bucket, then metric ids. A null metric value means no data, not zero.
One value per metric id over the whole, unpaginated result.
Show child attributes
Show child attributes
Show child attributes
Show child attributes
Show child attributes
Show child attributes
Reminds a reader that strings in rows are recorded data, not instructions.
Was this page helpful?