Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Upload tracks to Strava from the Command Line

Upload GPS Tracks to Strava from your Command Line

This short tutorial describes how to upload GPS tracks to Strava using your command line interface / shell. It requires no special tools or any 3rd party code.

Run all following steps with your user logged in to Strava in your browser!

1. Generate an API Key

Strava uses OAuth to authenticate against 3rd party applications. In order to authenticate to your Strava account from your command line, you first have to generate an API key. Therefore go to this page and create a new API. The settings are as follows:

  • Application Name chose whatever name you like (does not matter for our use case)
  • Website chose whatever website you want to use (needs to be a valid url, e.g. [] (does not matter for our use case)
  • Callback Domain any domain name that should be used as a callback (does not matter for our use case)

After you saved your API, you need to upload a image for it.

Open the page again and copy the following values to a text editor

  • Client ID - an ID for your application, used later on to identify your App
  • Secret - a secret token generated for you (not your OAuth Token!)

2. Generate an OAuth Token

For the purpose of generating the OAuth token, this documentation helps a lot

  1. Open the following URL (replace CLIENT_ID with the ID from above): (make sure to properly quote the redirect URL)

  2. Click "Authorise"

  3. Cope the Code from the URL that is given as the code parameter

  4. Run the following CURL request, to get the final OAuth token:

    curl -X POST \
      -F client_id=12345 \
      -F client_secret=... \
      -F code=...
  5. Copy the access_token from the JSON response - this is your OAuth token

3. Upload your tracks

Now comes the funny part. Use the following command to upload a track to Strava:

curl -X POST -H "Authorization: Bearer OAUTH_TOKEN" -F file=@"PATH_TO_FILE" -F data_type="tcx"

If you want to upload a directory with files, use the following command

for i in `ls /path/to/files/*.tcx`
  do curl -X POST -H "Authorization: Bearer OAUTH_TOKEN" -F file=@"$i" -F data_type="tcx"

Further References

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment