Run a cohort analysis
curl --request POST \
--url https://api.upstackdata.com/db-mgmt/api/query-cohort-analysis \
--header 'Content-Type: application/json' \
--header 'x-api-key: <api-key>' \
--header 'x-pixel-id: <api-key>' \
--data '
{
"pixelId": "<string>",
"measures": [],
"dateRange": {
"start": "2026-04-01",
"end": "2026-04-30"
},
"timezone": "<string>",
"filters": {
"and": [
{
"value": "<string>"
}
]
},
"orderSettings": {
"countPendingOrders": true,
"countVoidedOrders": true,
"exclusionFilters": [
{}
]
}
}
'import requests
url = "https://api.upstackdata.com/db-mgmt/api/query-cohort-analysis"
payload = {
"pixelId": "<string>",
"measures": [],
"dateRange": {
"start": "2026-04-01",
"end": "2026-04-30"
},
"timezone": "<string>",
"filters": { "and": [{ "value": "<string>" }] },
"orderSettings": {
"countPendingOrders": True,
"countVoidedOrders": True,
"exclusionFilters": [{}]
}
}
headers = {
"x-api-key": "<api-key>",
"x-pixel-id": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {
'x-api-key': '<api-key>',
'x-pixel-id': '<api-key>',
'Content-Type': 'application/json'
},
body: JSON.stringify({
pixelId: '<string>',
measures: [],
dateRange: {start: '2026-04-01', end: '2026-04-30'},
timezone: '<string>',
filters: {and: [{value: '<string>'}]},
orderSettings: {countPendingOrders: true, countVoidedOrders: true, exclusionFilters: [{}]}
})
};
fetch('https://api.upstackdata.com/db-mgmt/api/query-cohort-analysis', 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.upstackdata.com/db-mgmt/api/query-cohort-analysis",
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([
'pixelId' => '<string>',
'measures' => [
],
'dateRange' => [
'start' => '2026-04-01',
'end' => '2026-04-30'
],
'timezone' => '<string>',
'filters' => [
'and' => [
[
'value' => '<string>'
]
]
],
'orderSettings' => [
'countPendingOrders' => true,
'countVoidedOrders' => true,
'exclusionFilters' => [
[
]
]
]
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"x-api-key: <api-key>",
"x-pixel-id: <api-key>"
],
]);
$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.upstackdata.com/db-mgmt/api/query-cohort-analysis"
payload := strings.NewReader("{\n \"pixelId\": \"<string>\",\n \"measures\": [],\n \"dateRange\": {\n \"start\": \"2026-04-01\",\n \"end\": \"2026-04-30\"\n },\n \"timezone\": \"<string>\",\n \"filters\": {\n \"and\": [\n {\n \"value\": \"<string>\"\n }\n ]\n },\n \"orderSettings\": {\n \"countPendingOrders\": true,\n \"countVoidedOrders\": true,\n \"exclusionFilters\": [\n {}\n ]\n }\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("x-api-key", "<api-key>")
req.Header.Add("x-pixel-id", "<api-key>")
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.upstackdata.com/db-mgmt/api/query-cohort-analysis")
.header("x-api-key", "<api-key>")
.header("x-pixel-id", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"pixelId\": \"<string>\",\n \"measures\": [],\n \"dateRange\": {\n \"start\": \"2026-04-01\",\n \"end\": \"2026-04-30\"\n },\n \"timezone\": \"<string>\",\n \"filters\": {\n \"and\": [\n {\n \"value\": \"<string>\"\n }\n ]\n },\n \"orderSettings\": {\n \"countPendingOrders\": true,\n \"countVoidedOrders\": true,\n \"exclusionFilters\": [\n {}\n ]\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.upstackdata.com/db-mgmt/api/query-cohort-analysis")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["x-api-key"] = '<api-key>'
request["x-pixel-id"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"pixelId\": \"<string>\",\n \"measures\": [],\n \"dateRange\": {\n \"start\": \"2026-04-01\",\n \"end\": \"2026-04-30\"\n },\n \"timezone\": \"<string>\",\n \"filters\": {\n \"and\": [\n {\n \"value\": \"<string>\"\n }\n ]\n },\n \"orderSettings\": {\n \"countPendingOrders\": true,\n \"countVoidedOrders\": true,\n \"exclusionFilters\": [\n {}\n ]\n }\n}"
response = http.request(request)
puts response.read_body{
"results": [
{
"dimensions": [
"<string>"
],
"dateRange": {
"start": "2026-04-01",
"end": "2026-04-30"
},
"compareDateRange": {
"start": "2026-04-01",
"end": "2026-04-30"
},
"measureDetails": [
{
"measure": "<string>",
"isAverage": true,
"isPercentage": true,
"calculatedAverage": true,
"success": true,
"primaryAvg": 123,
"compareAvg": 123,
"primarySum": 123,
"compareSum": 123,
"percentDiff": 123,
"hasPacing": true
}
],
"data": {
"primary": [
{
"dt": "<string>",
"start": "<string>",
"end": "<string>"
}
],
"compare": [
{
"dt": "<string>",
"start": "<string>",
"end": "<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
Run a cohort analysis
Cohort an audience by acquisition period and analyze retention or LTV over time. Limited to cohort-specific measures and to weekly / monthly / yearly granularity.
Required scope: analytics:read.
POST
/
db-mgmt
/
api
/
query-cohort-analysis
Run a cohort analysis
curl --request POST \
--url https://api.upstackdata.com/db-mgmt/api/query-cohort-analysis \
--header 'Content-Type: application/json' \
--header 'x-api-key: <api-key>' \
--header 'x-pixel-id: <api-key>' \
--data '
{
"pixelId": "<string>",
"measures": [],
"dateRange": {
"start": "2026-04-01",
"end": "2026-04-30"
},
"timezone": "<string>",
"filters": {
"and": [
{
"value": "<string>"
}
]
},
"orderSettings": {
"countPendingOrders": true,
"countVoidedOrders": true,
"exclusionFilters": [
{}
]
}
}
'import requests
url = "https://api.upstackdata.com/db-mgmt/api/query-cohort-analysis"
payload = {
"pixelId": "<string>",
"measures": [],
"dateRange": {
"start": "2026-04-01",
"end": "2026-04-30"
},
"timezone": "<string>",
"filters": { "and": [{ "value": "<string>" }] },
"orderSettings": {
"countPendingOrders": True,
"countVoidedOrders": True,
"exclusionFilters": [{}]
}
}
headers = {
"x-api-key": "<api-key>",
"x-pixel-id": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {
'x-api-key': '<api-key>',
'x-pixel-id': '<api-key>',
'Content-Type': 'application/json'
},
body: JSON.stringify({
pixelId: '<string>',
measures: [],
dateRange: {start: '2026-04-01', end: '2026-04-30'},
timezone: '<string>',
filters: {and: [{value: '<string>'}]},
orderSettings: {countPendingOrders: true, countVoidedOrders: true, exclusionFilters: [{}]}
})
};
fetch('https://api.upstackdata.com/db-mgmt/api/query-cohort-analysis', 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.upstackdata.com/db-mgmt/api/query-cohort-analysis",
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([
'pixelId' => '<string>',
'measures' => [
],
'dateRange' => [
'start' => '2026-04-01',
'end' => '2026-04-30'
],
'timezone' => '<string>',
'filters' => [
'and' => [
[
'value' => '<string>'
]
]
],
'orderSettings' => [
'countPendingOrders' => true,
'countVoidedOrders' => true,
'exclusionFilters' => [
[
]
]
]
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"x-api-key: <api-key>",
"x-pixel-id: <api-key>"
],
]);
$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.upstackdata.com/db-mgmt/api/query-cohort-analysis"
payload := strings.NewReader("{\n \"pixelId\": \"<string>\",\n \"measures\": [],\n \"dateRange\": {\n \"start\": \"2026-04-01\",\n \"end\": \"2026-04-30\"\n },\n \"timezone\": \"<string>\",\n \"filters\": {\n \"and\": [\n {\n \"value\": \"<string>\"\n }\n ]\n },\n \"orderSettings\": {\n \"countPendingOrders\": true,\n \"countVoidedOrders\": true,\n \"exclusionFilters\": [\n {}\n ]\n }\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("x-api-key", "<api-key>")
req.Header.Add("x-pixel-id", "<api-key>")
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.upstackdata.com/db-mgmt/api/query-cohort-analysis")
.header("x-api-key", "<api-key>")
.header("x-pixel-id", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"pixelId\": \"<string>\",\n \"measures\": [],\n \"dateRange\": {\n \"start\": \"2026-04-01\",\n \"end\": \"2026-04-30\"\n },\n \"timezone\": \"<string>\",\n \"filters\": {\n \"and\": [\n {\n \"value\": \"<string>\"\n }\n ]\n },\n \"orderSettings\": {\n \"countPendingOrders\": true,\n \"countVoidedOrders\": true,\n \"exclusionFilters\": [\n {}\n ]\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.upstackdata.com/db-mgmt/api/query-cohort-analysis")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["x-api-key"] = '<api-key>'
request["x-pixel-id"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"pixelId\": \"<string>\",\n \"measures\": [],\n \"dateRange\": {\n \"start\": \"2026-04-01\",\n \"end\": \"2026-04-30\"\n },\n \"timezone\": \"<string>\",\n \"filters\": {\n \"and\": [\n {\n \"value\": \"<string>\"\n }\n ]\n },\n \"orderSettings\": {\n \"countPendingOrders\": true,\n \"countVoidedOrders\": true,\n \"exclusionFilters\": [\n {}\n ]\n }\n}"
response = http.request(request)
puts response.read_body{
"results": [
{
"dimensions": [
"<string>"
],
"dateRange": {
"start": "2026-04-01",
"end": "2026-04-30"
},
"compareDateRange": {
"start": "2026-04-01",
"end": "2026-04-30"
},
"measureDetails": [
{
"measure": "<string>",
"isAverage": true,
"isPercentage": true,
"calculatedAverage": true,
"success": true,
"primaryAvg": 123,
"compareAvg": 123,
"primarySum": 123,
"compareSum": 123,
"percentDiff": 123,
"hasPacing": true
}
],
"data": {
"primary": [
{
"dt": "<string>",
"start": "<string>",
"end": "<string>"
}
],
"compare": [
{
"dt": "<string>",
"start": "<string>",
"end": "<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>"
]
}
]
}Authorizations
Your Upstack API key. Starts with upstack_.
The pixel id the request targets.
Body
application/json
Must match the x-pixel-id header.
Available options:
week, month, year Cohort-specific measure ids. Pass measure ids as strings (this
endpoint differs from /api/query, which takes objects with
pacing).
Required array length:
1 - 30 elementsAvailable options:
orders.ltv_cohort_gross_revenue, orders.ltv_cohort_net_revenue, orders.customers_cohort, orders.avg_order_value_cohort, orders.cohort_retention_percent, orders.cohort_cm1, orders.cohort_cm2 Show child attributes
Show child attributes
Canonical filter applied to the cohort. orders.* fields
are valid in this context — discover via
GET /api/filters.
- Option 1
- Option 2
- Option 3
Show child attributes
Show child attributes
Order-level query settings — exclusion filters, pending/voided handling.
Show child attributes
Show child attributes
Response
Cohort results.
Show child attributes
Show child attributes
Was this page helpful?
⌘I