Jarkko Tervonen

Export GPX/TCX files from Garmin Connect

· Jarkko Tervonen

A few days ago, I requested all of my data from Garmin. The reason for that was that I would like to take backups from all my GPX files. Unfortunately, data export did not include GPX or TCX files.

After Googling around, the only way to export GPX files was to download them from the web GUI. Luckily, there was a ready-made script in the Garmin forums that did the trick. It worked almost the same way what I used to downloading Sports Tracker files.

First of all, you must log in to Garmin Connect. After that, go to the activities page and open developer tools. After that, copy and paste the following code to the console.

1h = {
2  'DI-Backend': 'connectapi.garmin.com',
3  'Authorization': 'Bearer ' + JSON.parse(localStorage.token).access_token

When code is executed, copy and paste the following code into the console. This will download all of your activities as GPX files. Remove the second line from the code if you want to download TCX files instead of GPX files. You can also modify the interval and limit variables to your liking.

 1var type = 'gpx';
 2var type = 'tcx'; // Remove this line if you want to download GPX files instead of TCX files
 3var interval = 1000;
 4var limit = 10000;
 6fetch('https://connect.garmin.com/activitylist-service/activities/search/activities?limit=' + limit,
 7  { 'headers': h }).then((r) => r.json()).then((all) => {
 8    t = 0
 9    all.forEach(async (a) => {
10      await new Promise(s => setTimeout(s, t += interval))
11      fetch('https://connect.garmin.com/download-service/export/' + type + '/activity/' + a.activityId,
12        { 'headers': h }).then((r) => r.blob()).then((b) => {
13          console.dir(a.activityId)
14          f = document.createElement('a')
15          f.href = window.URL.createObjectURL(b)
16          f.download = a.activityId
17          f.click()
18        })
19    })
20  })

In the future, I must find a way to track what files have already been downloaded. I found a few projects from GitHub that can be useful. Maybe the best ones were GarminDB and garth.