πŸƒβ€β™‚οΈ backup amazfit fitness tracking data πŸƒβ€β™‚οΈ

Christian Ott
πŸƒβ€β™‚οΈ backup amazfit fitness tracking data πŸƒβ€β™‚οΈ

Where is the data?

Even chinese data hoarder’s need to comply with GDPR. So some data can be downloaded from here:

https://user.huami.com/privacy/index.html

Make sure to use the same account to login as you did with the official Zepp app.

The generated zip file has a lot of interesting data, but does not include the sport activities with it’s GPX files.

When the official app can do it, there must be a way to access this activity data. A short search found a blog post which does exactly what I was looking for.

Zepp uses api-mifit.huami.com" or a localized variant (api-mifit-de2") to send data into the wild. We use it to get it back:

1. Find an apptoken

In the blog post, this is done by reading out the Zepp App settings (when rooted) or by sniffing HTTP traffic.

I took it from the cookie that was stored in the browser when I logged into: https://user.huami.com/privacy/index.html


      app token
    

2. Get a list of activities

Use the api-mifit-huami.com/v1/sport/run/history.json endpoint.

curl -i -X GET \
    -H "apptoken:<YOURTOKEN>" \
    -H "appPlatform:web" \
    -H "appname:com.xiaomi.hm.health" \
    'https://api-mifit.huami.com/v1/sport/run/history.json?'  | jq .

If you have more than 200 activities you need to manually page through by specifying start/stop TrackID’s. The TrackID’s of the runs are UNIX timestamps.

  • startTrackId=<earliestTrackId> Use a UNIX time stamp before your first activity
  • stopTrackId=<nextFromRespons> Use the TrackID in the next field of the `history.json

The history.json contains summaries of each run. We need more details to get a GPX out of an activity.

3. Get a list of activity details

Use api-mifit-huami.com/v1/sport/run/detail.json with the same header as before. But add the trackid and source parameter.

curl -i -X GET \
    -H "apptoken:<YOURTOKEN>" \
    -H "appPlatform:web" \
    -H "appname:com.xiaomi.hm.health" \
    'https://api-mifit.huami.com/v1/sport/run/detail.json?trackid=<TRACKID>&source=<SOURCE SUMMARY>'  | jq .

4. Export to GPX

The data in the detail.json is condensed. It starts with an absolute data point, each following data point is the relative difference to the previous data point. To get a GPX file out of it, the data must be summed up.

heartrate: [89,10,-5,7]
# which is summed up is
heartrate: [89,99,94,101] 

The author of the blog post created a cool tool which does all the work for us: Mi-Fit-and-Zepp-workout-exporter.

I fixed a small bug where the created GPX had the wrong timestamp in the track points.

Also, the data model of the activity summary was incomplete (for Amazfit GTR 3) and incompatible with the Amazfit Stratos Model 1619. Because these are model specific changes, I did the changes only in my fork. I modified the app to write out the raw summary/detail data, because the GPX contains only a subset of the available data, and I may want to use more data in the future.

5. Conclusion

Thanks to the great work in the blog post, exporting the Amazfit data was quite easy. Some amendments to the code, and I could successfully export all available data:

app token

Next steps: find a suitable replacement for Strava. FitTrackee looks promising.