for Users if I want add more fileds from my database such as total orders for each users and be update I need to know steps
Hi Anhar 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
To add and keep updated custom fields like "total orders" from your database to Mixpanel user profiles, follow these steps: 1. Extract Data from Your Database
Write a script to pull user data from your database, including the unique user ID (to be used as Mixpanel's distinct_id) and the custom field(s) you want to add or update (e.g., total_orders).2. Format Data for Mixpanel
Transform your user data into the format expected by Mixpanel's Engage API. For each user, create a dictionary/object with at least:
- $distinct_id: the unique user identifier (should match the one used in your event tracking)
- $set: an object containing the properties to update, e.g., {"total_orders": 42} Example in Python:
distinct_id = user.pop("user_id")
return {
"$distinct_id": distinct_id,
"$token": PROJECT_TOKEN,
"$ip": "0",
"$set": user # user dict now contains total_orders, etc.
}
```LBKS [See full example here](https://docs.mixpanel.com/guides/strategic-playbooks/project-migration#optional-step-8-import-users)LBKS3. **Send Data to Mixpanel**
Use the [Engage API](https://developer.mixpanel.com/reference/profile-set) to send the profile updates. You can batch up to 200 profiles per request for efficiency.LBKS Example using Python and `requests`:
```LBKS import json
import requestsLBKS profiles = [transform_to_mp_format(u) for u in users]
resp = [requests.post](http://requests.post)(
"[https://api.mixpanel.com/engage](https://api.mixpanel.com/engage)",
params={"verbose": "2"},
headers={"Content-Type": "application/json"},
data=json.dumps(profiles)
)
print(resp.json())
```LBKS [Reference: Import Users Guide](https://docs.mixpanel.com/guides/strategic-playbooks/project-migration#optional-step-8-import-users)LBKS4. **Schedule Regular Updates**
To keep the field (like `total_orders`) up to date, schedule your script to run periodically (e.g., hourly or daily), so Mixpanel always has the latest values from your database.LBKS**Important Notes:**
- Make sure the `distinct_id` you use matches the one used in your event tracking, so profile data joins correctly with events.
- You can update any custom property this way, and Mixpanel will always show the latest value for each property on the user profile [User Profiles FAQ](https://docs.mixpanel.com/docs/data-structure/user-profiles#faq).LBKSThis approach works for any custom field you want to sync from your database to Mixpanel user profiles.
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.
