Jarkko Tervonen

Export data from Sports Tracker without the app

· Jarkko

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.

var type = "gpx";
var type = "fit"; // Remove this line if you want export GPX files

var showMore = null;
while (showMore = document.querySelector("div.show-more")) {
  if (showMore.classList.contains("ng-hide")) {
    break;
  }
  showMore.click();
  await new Promise(r => setTimeout(r, 1000));
}

var workouts = document.querySelectorAll("ul.diary-list__workouts li a");
var token = RegExp("sessionkey" + "=[^;]+")
  .exec(document.cookie)
  .toString()
  .replace(/^[^=]+./, "");
var output = "";

var batch = 0;
for (i = 0; i < workouts.length; i++) {
  if (i % 24 == 0) {
    batch++;
  }

  var href = workouts[i].href;
  var id = href.substr(href.lastIndexOf("/") + 1, 24);

  var url =
    "https://api.sports-tracker.com/apiserver/v1/workout/" +
    (type == "gpx" ? "exportGpx" : "exportFit") +
    "/" +
    id +
    "?token=" +
    token;
  var filename = batch + "-" + "sports-tracker-" + id + "." + type;

  fetch(url)
  .then(resp => resp.blob())
  .then(blob => {
    const url = window.URL.createObjectURL(blob);
    const a = document.createElement("a");
    a.style.display = "none";
    a.href = url;
    a.download = filename;
    document.body.appendChild(a);
    a.click();
    window.URL.revokeObjectURL(url);
  })
  .catch(() => alert("Something went wrong when downloading files"));

  await new Promise(r => setTimeout(r, 1000));
}

console.log("Done.");

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

#tech