So, this curl request works
curl 'https://data.mixpanel.com/api/2.0/export?project_id=3732260&from_date=2025-09-08&to_date=2025-09-14' \
--header 'accept: text/plain' \
--user 'my-user.12345.mp-service-account:SERVICE_ACCOUNT_SECRET'
it seems the way we are sending auth isn't working. Any different way to sending auth then? kapa.ai
Here is script, I'm trying, but it still seems to throw error too
import requests
from requests.auth import HTTPBasicAuth
from datetime import datetime, timedelta
# --- Configuration ---
service_account_username = "" # Replace
service_account_password = "" # Replace
project_id = 3732260 # Replace with your integer project ID
output_filename = "mixpanel_weekly_export.jsonl"
# --- Calculate Last Week's Date Range (Monday to Sunday) ---
today = datetime.today()
last_monday = today - timedelta(days=today.weekday() + 7)
last_sunday = last_monday + timedelta(days=6)
from_date = last_monday.strftime("%Y-%m-%d")
to_date = last_sunday.strftime("%Y-%m-%d")
# --- Build API URL ---
api_url = f"https://data.mixpanel.com/api/2.0/export?project_id={project_id}&from_date={from_date}&to_date={to_date}"
# api_url = f"https://api.mixpanel.com/"
# --- Fetch Data ---
print(f"📅 Fetching Mixpanel data from {from_date} to {to_date}...")
response = requests.get(
api_url,
auth=HTTPBasicAuth(service_account_username, service_account_password),
headers={"Accept": "text/plain", "Accept-Encoding": "gzip"}, # gzip optional; server may gzip large responses
timeout=180
)
# --- Handle Response ---
if response.status_code == 200:
with open(output_filename, "w", encoding="utf-8") as f:
f.write(response.text)
print(f"✅ Data saved to {output_filename}")
else:
print(f"❌ Failed to fetch data. HTTP {response.status_code}")
print("🔍 Details:", response.text)
print("Response: ", response)
It throws this error 📅 Fetching Mixpanel data from 2025-09-08 to 2025-09-14... ❌ Failed to fetch data. HTTP 400 🔍 Details: Unable to authenticate request Is there way to get more detailed logs of error as well? kapa.ai
How do I export raw data for mixpanel? I've this script, but it keeps throwing 400 error and fails on authenication
import requests
from requests.auth import HTTPBasicAuth
from datetime import datetime, timedelta
# --- Configuration ---
service_account_username = "service_account" # Replace
service_account_password = "service_password" # Replace
project_id = 3732260 # Replace with your integer project ID
output_filename = "mixpanel_weekly_export.csv"
# --- Calculate Last Week's Date Range (Monday to Sunday) ---
today = datetime.today()
last_monday = today - timedelta(days=today.weekday() + 7)
last_sunday = last_monday + timedelta(days=6)
from_date = last_monday.strftime("%Y-%m-%d")
to_date = last_sunday.strftime("%Y-%m-%d")
# --- Build API URL ---
api_url = f"https://data.mixpanel.com/api/2.0/export?project_id={project_id}&from_date={from_date}&to_date={to_date}"
# api_url = f"https://api.mixpanel.com/"
# --- Fetch Data ---
print(f"📅 Fetching Mixpanel data from {from_date} to {to_date}...")
response = requests.get(
api_url,
auth=HTTPBasicAuth(service_account_username, service_account_password),
timeout=180
)
# --- Handle Response ---
if response.status_code == 200:
with open(output_filename, "w", encoding="utf-8") as f:
f.write(response.text)
print(f"✅ Data saved to {output_filename}")
else:
print(f"❌ Failed to fetch data. HTTP {response.status_code}")
print("🔍 Details:", response.text)
print("Response: ", response)
