Whats wrong with this export api 'where' field? <?php require_once('vendor/autoload.php'); $client = new \GuzzleHttp\Client(); $response = $client->request('GET', 'https://data-eu.mixpanel.com/api/2.0/export?project_id=3334207&from_date=2025-12-28&to_date=2025-12-28&limit=1&event=%5B%22checkout%22%5D&where=%27distinct_id%20%3D%3D%20%223147%22%27', [ 'headers' => [ 'accept' => 'text/plain', ], ]); echo $response->getBody(); It's returning error 400
Hi Gustavo S., Please stand by as I search the Mixpanel knowledge base for an AI-powered answer. I normally take about 15 seconds or so. In case AI cannot answer your question, feel free to reach out to Mixpanel support at mixpanel.com/get-support. If you have follow-up questions for this thread, please tag me again with your question: @kapa.ai <follow-up question> 👋
Feel free to ask a follow-up question once I've answered by mentioning me with @kapa.ai
Your where expression is malformed for the Raw Event Export API.
1. where must use the segmentation expression grammar – you can’t filter directly on distinct_id like distinct_id == "3147". It must reference properties, e.g.:
txt
properties["distinct_id"] == "3147"
The Export API’s where parameter uses the same expression syntax as Segmentation / Raw Export, which is documented as properties<https://github.com/mixpanel/docs/blob/main/reference/Mixpanel%20APIs/segmentation-expressions.md%7C%22<property_name/%22] .... [[Segmentation expr> ; Export API]
2. You’re URL‑encoding extra quotes – in your URL you have:
txt
where=%27distinct_id%20%3D%3D%20%223147%22%27
That decodes to 'distinct_id == "3147"' (note the outer single quotes). The expression should not be wrapped in quotes; only the string literal needs quotes.
Use this instead (note: only the expression is URL‑encoded, no outer quotes, and using properties["distinct_id"]):
```
kapa.ai is still learning and improving, please let me know how I did by reacting below.
ℹ️ Tip: Mention @kapa.ai in the thread for follow-ups or DM the app for 1-to-1 help.
this code still doesn't work:
$projectId = 3334207;
$fromDate = '2025-12-28';
$toDate = '2025-12-28';
$eventName = 'checkout';
$distinctId = '4612';
$where = urlencode('properties["distinct_id"] == "3147"');
$response = $client->request('GET', 'https://data-eu.mixpanel.com/api/2.0/export', [
'http_errors' => false, // IMPORTANT: lets you read the body on 400
'auth' => [$username, $secret], // better than hardcoding a base64 header
'headers' => [
'accept' => 'text/plain',
],
'query' => [
'project_id' => $projectId,
'from_date' => $fromDate,
'to_date' => $toDate,
'limit' => 1,
'event' => json_encode([$eventName]), // must be JSON array :contentReference[oaicite:1]{index=1}
"where={$where}",
],
]);
echo "HTTP: " . $response->getStatusCode() . "\n";
echo (string) $response->getBody();
