Reverse Engineering Mi Fit API to Access Your Fitness Data from the app
- A spare Android device (version >= 7.1.1)
- Root access via Magisk (or another root/superuser method)
- If using Magisk, ensure you have the
MagiskTrustUserCertsmodule installed and activated - Alternatively, use a tool like "certInstaller [Root]" for cert installation
- If using Magisk, ensure you have the
- mitmproxy (must be on the same network as the Android device)
- Install the Mi Fit app on your Android device (from the Play Store or APK).
- On your PC, run mitmproxy to intercept HTTP(S) traffic.
- Copy mitmproxy's root CA certificate to your Android device (this can be done via email, USB file transfer, or ADB push).
- Import the certificate into your Android device.
- On devices with Android >7.1.1 and the Magisk module or "certInstaller [Root]", reboot the device after importing to ensure the cert works as a system certificate.
- On the Android device, open Wi-Fi settings, select the connected network, and configure it to use mitmproxy as the proxy (set mitmproxy’s IP and port).
- Ensure internet traffic, including HTTPS requests, flows through mitmproxy.
- Log in to your Mi Fit account (e.g., using email).
- Monitor the traffic in mitmproxy to intercept the API calls.
- A POST request is made to
https://api-user.huami.com/registrations/[EMAIL-ADDRESS]/tokens. - The request uses URL encoding, and the password is sent in plain text.
- Required fields:
state: 'REDIRECTION'client_id: 'HuaMi'redirect_uri:https://s3-us-west-2.amazonws.com/hm-registration/successsignin.htmltoken: 'access'password: [your password]
- The response contains a redirect URI with URL parameters including
access(the access token) andcountry_code.
- A POST request is sent to
https://account.huami.com/v2/client/login. - Required fields:
app_name: 'com.xiaomi.hm.health'country_code: [from the previous step]code: [access token]device_id: '02:00:00:00:00:00'device_model: 'android_phone'grant_type: 'access_token'third_name: 'huami'lang: 'de'
- On success, the response returns a JSON object containing the
login_token,app_token, anduser_id. These values are used for further API communication.
- A GET request is made to
https://api-mifit.huami.com/v1/data/band_data.json. - Required GET parameters:
query_type: 'summary'device_type: 'android_phone'userid: [user_id from the previous step]from_date: '2019-01-01'to_date: '2019-12-31'
- A header
apptokenmust be set with theapp_tokenfrom the API credentials.
The response contains daily fitness data for the specified period. The summary field for each day contains a BASE64-encoded JSON structure.
After decoding, the following information is available:
-
Step Data (
stp):ttl: Total steps for the daydis: Total distance walked (in meters)cal: Calories burnedstage: List of individual activities (e.g., walking, running) with detailed information:start: Start time (minutes since midnight)end: End timestep: Number of steps during the activitydis: Distance in meterscal: Calories burned during the activitymode: Activity type (1 = walking, 7 = normal steps, others TBD)
-
Sleep Data (
slp):st: Start of sleep (epoch seconds)ed: End of sleep (epoch seconds)dp: Deep sleep duration (in minutes)lt: Light sleep duration (in minutes)stage: List of sleep phases with details:start: Start time of the phase (minutes since midnight)end: End time of the phasemode: Sleep type (4 = light sleep, 5 = deep sleep, others TBD)
To run the script:
./mifit_api.py --email me@mydomain.com --password s3cr3t