I tried exporting all users; but am unable to do so. I tried exporting based on the number of pages; but it did not work out. This code only exports 1000 users and returns Error500.
import requests
import json
url = "https://mixpanel.com/api/2.0/engage?project_id="
headers = {
"accept": "application/json",
"content-type": "application/x-www-form-urlencoded",
"authorization": "Basic "
}
all_users = []
page = 0
while True:
payload = {
"include_all_users": True,
"page": page
}
response = requests.post(url, data=payload, headers=headers)
if response.status_code == 200:
data_json = json.loads(response.text)
users = data_json['results']
if not users:
break
all_users.extend(users)
page += 1
else:
print("Error:", response.status_code)
break
with open('exported_User_data.json', 'w', encoding='utf-8') as jsonfile:
json.dump(all_users, jsonfile, ensure_ascii=False)
print(f"Exported {len(all_users)} users to exported_User_data.json")
Your help to solve this probel will grately be appreciated. Thank you!