Jarkko Tervonen

Export data from Sports Tracker without the app

· Jarkko Tervonen

Seems like it’s impossible to request all data from Sports Tracker without installing the app. Their support pages says asking for all data from the app is possible. However, they do not inform us of any other way to request the data.

About two years ago, I wrote a blog post to my Finnish blog on how to export all GPX files from the Sports Tracker. Today, I downloaded again all my GPX files just for a backup if the Sports Tracker is shut down in the future. Old instructions and code snippets worked well. So here are the instructions on downloading all GPX files from the Sports Tracker.

First of all, go to the workout list page. After that, open the console tab from the developer tools. Copy the following code in the console and wait until all workouts are downloaded into your downloads folder.

 1var type = "gpx";
 2var type = "fit"; // Remove this line if you want export GPX files
 3
 4var showMore = null;
 5while (showMore = document.querySelector("div.show-more")) {
 6  if (showMore.classList.contains("ng-hide")) {
 7    break;
 8  }
 9  showMore.click();
10  await new Promise(r => setTimeout(r, 1000));
11}
12
13var workouts = document.querySelectorAll("ul.diary-list__workouts li a");
14var token = RegExp("sessionkey" + "=[^;]+")
15  .exec(document.cookie)
16  .toString()
17  .replace(/^[^=]+./, "");
18var output = "";
19
20var batch = 0;
21for (i = 0; i < workouts.length; i++) {
22  if (i % 24 == 0) {
23    batch++;
24  }
25
26  var href = workouts[i].href;
27  var id = href.substr(href.lastIndexOf("/") + 1, 24);
28
29  var url =
30    "https://api.sports-tracker.com/apiserver/v1/workout/" +
31    (type == "gpx" ? "exportGpx" : "exportFit") +
32    "/" +
33    id +
34    "?token=" +
35    token;
36  var filename = batch + "-" + "sports-tracker-" + id + "." + type;
37
38  fetch(url)
39  .then(resp => resp.blob())
40  .then(blob => {
41    const url = window.URL.createObjectURL(blob);
42    const a = document.createElement("a");
43    a.style.display = "none";
44    a.href = url;
45    a.download = filename;
46    document.body.appendChild(a);
47    a.click();
48    window.URL.revokeObjectURL(url);
49  })
50  .catch(() => alert("Something went wrong when downloading files"));
51
52  await new Promise(r => setTimeout(r, 1000));
53}
54
55console.log("Done.");

Your browser might asks for access to download multiple files at once.

#tech