Skip to main content

Hi Strava community!

On my account, it is possible to manually export a GPX file of an activity (not a route, an activity). This GPX file can then be imported in another app (specific for biking stats for example).

Is there a way to do it programmatically? On the API documentation, I saw that there is an endpoint to extract GPX for a route but not for an activity.

I've understood how to get the list of activities I am looking for from the public API and their ids, but is there a way to get the GPX file from a specific activity?

I also haven't found parameters to filter the activity list we can get from the GET activity endpoind (to search for ride activities only for example). This is available using the desktop app.

Is there a way to do this? Thank you for your answers.

I don't think there's any direct way to get the GPX/TCX, but hopefully someone more knowledgeable can chime in.

Assuming there isn't, you can build one yourself using the activity stream data. You can use getActivityStreams to request all of the data streams for the activity, then pack that data into the file format you want. There are libraries available in most languages to write GPX/TCX/FIT files so it would just be a matter of taking the data returned from getActivityStreams and getting it into the format needed from whatever library you decide to use. It's not an ideal solution but could work if I'm correct about there being no API call to export the GPX file.

 

As to your second question, I don't think there's a way to filter the activities from the API call directly. Instead you would use getLoggedInAthleteActivities to get a list of activities and on your backend (or frontend) filter the results by the sport_type field.


I just have a similar problem, I think it's possible, however without timestamps.


I'm adding this because I think it might be helpful as I had the same problem for one of my projects. It is true that you cannot directly get a gpx file with the current Strava API, but there are libraries out there that can help.

For example, I have created a python library strava2gpx that lets you put in an activity id to get a gpx file back. It calls the data streams from the Strava API to generate a gpx file. There are options to customize the name of the file and it will grab additional fields like heart rate or cadence. There is also functionality to get lists of activities with parameters that you can sort by like type or date/time.

The goal of the library is simplicity. The github has some examples in the documentation and I wrote a short tutorial on the usage here. You can install strava2gpx with the following command

pip install strava2gpx


Hopefully this is helpful to anyone who runs into this same problem


Reply