I am sending a request like the following in python:
url = "https://data.mixpanel.com/api/2.0/export?project_id=<redacted>&from_date=2025-04-01&to_date=2025-04-01&limit=100000&event=streaks_reward_page"
response = requests.get(
url,
auth=(self.api_secret, ''),
timeout=180,
)
I have verified the project_id works because I can make requests to the engage endpoint and I get a response. What is the issue?
Based on your code snippet, I can see a few potential issues with your Raw Event Export API request. Let me help you troubleshoot: 1. URL Formatting Issue: Your URL appears to have HTML encoding issues with <https://
and <redacted>
. The correct format should be a plain URL without these HTML tags.2. Authentication Method: You're using the Project Secret authentication method (which is being deprecated, though still supported). Make sure your api_secret
is correct.3. Date Range: You're requesting data for April 1, 2025, which is in the future. The API can only export historical data.4. Rate Limits: The Raw Event Export API has specific rate limits that might be affecting your request:
- 60 queries per hour
- 3 queries per second
- Maximum of 100 concurrent queriesIf you exceed these limits, you'll receive a 429 error response. Rate Limits5. Event Existence: Verify that the event "streaks_reward_page" exists in your project for the specified date range.Here's a corrected version of your code: LBKSurl = "[https://data.mixpanel.com/api/2.0/export](https://data.mixpanel.com/api/2.0/export)" params = { "project_id": "your_project_id", "from_date": "2023-04-01", # Use a past date "to_date": "2023-04-01", "limit": 100000, "event": '["streaks_reward_page"]' # Event should be a JSON array }LBKSresponse = requests.get( url, params=params, auth=(self.api_secret, ''), timeout=180, )LBKS
Note that the event
parameter should be a JSON array, even for a single event. Also, consider using the mixpanel-utils Python library which handles many of these details for you.If you're still having issues, check the response status code and message for more specific error information.
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.
kapa.ai to respond to all of your points:
URL Formatting Issue: Your URL appears to have HTML encoding issues with <https:// and <redacted>. The correct format should be a plain URL without these HTML tags. - Obviously I am not using html tags. Just the project_id which works on other requests.
Authentication Method: You’re using the Project Secret authentication method (which is being deprecated, though still supported). Make sure your api_secret is correct. - The api_secret is correct, I use it on other api endpoints.
Date Range: You’re requesting data for April 1, 2025, which is in the future. The API can only export historical data. - Today’s date is April 4th 2025
Rate Limits: The Raw Event Export API has specific rate limits that might be affecting your request - I receive a 400, not a 429
Event Existence: Verify that the event “streaks_reward_page” exists in your project for the specified date range. - Yes that event exists.
Using your code, I still receive a 400 level response Error exporting events: invalid parameter: project_id
Let me check the knowledge base for you again. One moment! 📚
I see the issue now. Based on your additional information, let's focus on the specific error you're receiving: Error exporting events: invalid parameter: project_id
.This error suggests there's a problem with how the project_id is being passed to the Raw Event Export API. Here are some specific things to check: 1. Project ID Format: Make sure your project_id is being passed as an integer or a string that can be parsed as an integer. The documentation indicates that project_id should be an integer value.2. Authentication Method: When using Service Account authentication with the Raw Event Export API, you must include the project_id as a query parameter. The documentation specifically states: "Note that when you use Service Account authentication, you must specify the project_id as a query parameter." Authentication3. API Endpoint: Verify you're using the correct endpoint for your project's data residency:
- Standard: [data.mixpanel.com/api/2.0/export](http://data.mixpanel.com/api/2.0/export)
- EU Residency: [data-eu.mixpanel.com/api/2.0/export](http://data-eu.mixpanel.com/api/2.0/export)
- India Residency: [data-in.mixpanel.com/api/2.0/export](http://data-in.mixpanel.com/api/2.0/export)
Try modifying your request to ensure the project_id is properly formatted: LBKSurl = "[https://data.mixpanel.com/api/2.0/export](https://data.mixpanel.com/api/2.0/export)" params = { "project_id": 12345, # Make sure this is an integer or a string that represents an integer "from_date": "2025-04-01", "to_date": "2025-04-01", "limit": 100000, "event": "streaks_reward_page" # Single event can be passed as string }LBKSresponse = requests.get( url, params=params, auth=(self.api_secret, ''), timeout=180, )LBKS
If you're still encountering issues, you might want to try using the MixpanelUtils library which handles many of these details: LBKSfrom mixpanel_utils import MixpanelUtilsLBKSmputils = MixpanelUtils( 'YourServiceAccountSecret', service_account_username='your-user.12345.mp-service-account', project_id=12345 )LBKSmputils.export_events('event_export.txt', { 'from_date': '2025-04-01', 'to_date': '2025-04-01', 'event': '["streaks_reward_page"]' })LBKS
This approach might help bypass some of the common issues with the raw API calls.
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.