Query API
Cohorts
List and query user cohorts
POST
/
api
/
query
/
cohorts
/
list
Cohorts
curl --request POST \
--url https://mixpanel.com/api/query/cohorts/listimport requests
url = "https://mixpanel.com/api/query/cohorts/list"
response = requests.post(url)
print(response.text)const options = {method: 'POST'};
fetch('https://mixpanel.com/api/query/cohorts/list', 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://mixpanel.com/api/query/cohorts/list",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://mixpanel.com/api/query/cohorts/list"
req, _ := http.NewRequest("POST", url, nil)
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://mixpanel.com/api/query/cohorts/list")
.asString();require 'uri'
require 'net/http'
url = URI("https://mixpanel.com/api/query/cohorts/list")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
response = http.request(request)
puts response.read_body{
"count": 123,
"is_visible": 123,
"description": "<string>",
"created": "<string>",
"project_id": 123,
"id": 123,
"name": "<string>"
}Query Cohorts
List saved cohorts and retrieve cohort membership information.List Saved Cohorts
integer
required
Your Mixpanel project ID
integer
The workspace ID
Example Request
curl "https://mixpanel.com/api/query/cohorts/list?project_id=123" \
-X POST \
-u SERVICE_ACCOUNT_USERNAME:SERVICE_ACCOUNT_SECRET
import requests
from requests.auth import HTTPBasicAuth
response = requests.post(
'https://mixpanel.com/api/query/cohorts/list',
auth=HTTPBasicAuth('SERVICE_ACCOUNT_USERNAME', 'SERVICE_ACCOUNT_SECRET'),
params={'project_id': 123}
)
cohorts = response.json()
for cohort in cohorts:
print(f"{cohort['name']}: {cohort['count']} users")
Response
integer
Number of users currently in the cohort
integer
Visibility status (0 = not visible, 1 = visible)
string
Cohort description
string
Creation timestamp
integer
Project ID
integer
Cohort ID
string
Cohort name
[
{
"count": 150,
"is_visible": 1,
"description": "Power users who logged in 10+ times",
"created": "2024-01-15 10:30:00",
"project_id": 123,
"id": 1000,
"name": "Power Users"
},
{
"count": 2500,
"is_visible": 1,
"description": "Users who signed up in January",
"created": "2024-01-01 09:00:00",
"project_id": 123,
"id": 1001,
"name": "January Signups"
}
]
Query Cohort Members
Use the/engage endpoint with filter_by_cohort parameter to get users in a cohort:
import requests
from requests.auth import HTTPBasicAuth
response = requests.post(
'https://mixpanel.com/api/query/engage',
auth=HTTPBasicAuth('USERNAME', 'SECRET'),
params={'project_id': 123},
data={
'filter_by_cohort': '{"id": 1000}'
}
)
users = response.json()
print(f"Total users: {users['total']}")
for user in users['results']:
print(f"User: {user['$distinct_id']}")
⌘I
Cohorts
curl --request POST \
--url https://mixpanel.com/api/query/cohorts/listimport requests
url = "https://mixpanel.com/api/query/cohorts/list"
response = requests.post(url)
print(response.text)const options = {method: 'POST'};
fetch('https://mixpanel.com/api/query/cohorts/list', 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://mixpanel.com/api/query/cohorts/list",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://mixpanel.com/api/query/cohorts/list"
req, _ := http.NewRequest("POST", url, nil)
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://mixpanel.com/api/query/cohorts/list")
.asString();require 'uri'
require 'net/http'
url = URI("https://mixpanel.com/api/query/cohorts/list")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
response = http.request(request)
puts response.read_body{
"count": 123,
"is_visible": 123,
"description": "<string>",
"created": "<string>",
"project_id": 123,
"id": 123,
"name": "<string>"
}