In the API how do I do a where for user id
To filter profiles by a specific user ID using the Engage API, you use the where parameter with a segmentation expression, or you can use the distinct_id or distinct_ids parameters directly.
Option 1: Use distinct_id parameter
Pass the user's distinct ID directly:
POST https://mixpanel.com/api/query/engage?project_id=YOUR_PROJECT_ID
Content-Type: application/x-www-form-urlencoded
distinct_id=YOUR_USER_IDOption 2: Use distinct_ids for multiple users
POST https://mixpanel.com/api/query/engage?project_id=YOUR_PROJECT_ID
Content-Type: application/x-www-form-urlencoded
distinct_ids=["id1", "id2"]Option 3: Use the where expression
You can filter using a segmentation expression with the where parameter:
where=properties["$distinct_id"] == "YOUR_USER_ID"Example (curl)
curl --request POST \
--url 'https://mixpanel.com/api/query/engage?project_id=YOUR_PROJECT_ID' \
--header 'accept: application/json' \
--header 'authorization: Basic YOUR_TOKEN' \
--header 'content-type: application/x-www-form-urlencoded' \
--data 'distinct_id=YOUR_USER_ID'Note: For projects using the Simplified ID Merge API, the canonical distinct_id is always set to the $user_id after identification. [Identifying Users] So make sure you're querying by the canonical distinct_id (i.e., the $user_id value you passed to identify()).
โน๏ธย Tip: Mention @kapa.ai in the thread for follow-ups or DM the app for 1-to-1 help.
The Engage API returns results in pages, with a default page_size of 1000 records per request. If you're only getting 31 results, it's likely not a pagination issue โ but rather that your query is only matching 31 profiles.
However, if you believe there should be hundreds of results, the most common cause is that the API returns paginated results and you need to iterate through pages to get all of them. Here's how pagination works: [Query Profiles]
// Get the first page of data
this_page = query_api(where=YOUR_SELECTOR_EXPRESSION)
do_something_with_response(this_page)
// Keep querying if results equal page_size
while (length of this_page.results) >= this_page.page_size:
next_page_number = this_page.page + 1
this_page = query_api(
where=YOUR_SELECTOR_EXPRESSION,
session_id=this_page.session_id,
page=next_page_number
)
do_something_with_response(this_page)Key points:
Use the session_id from the first response in subsequent requests.
Increment the page parameter for each subsequent request.
Stop when the number of results returned is less than page_size.
Also note that the Engage API has a rate limit of 60 queries per hour and a maximum of 5 concurrent queries, so be mindful of that when paginating through large datasets. [Query Profiles]
If pagination isn't the issue, double-check your where filter or distinct_id parameter โ it may be narrowing results more than intended.
โน๏ธย Tip: Mention @kapa.ai in the thread for follow-ups or DM the app for 1-to-1 help.
