Skip to content

Instantly share code, notes, and snippets.

@michaellihs
Last active July 26, 2025 19:45
Show Gist options
  • Save michaellihs/bb262e2c6ee93093485361de282c242d to your computer and use it in GitHub Desktop.
Save michaellihs/bb262e2c6ee93093485361de282c242d to your computer and use it in GitHub Desktop.

Revisions

  1. michaellihs revised this gist May 4, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion strava_cli.md
    Original file line number Diff line number Diff line change
    @@ -63,7 +63,7 @@ curl -X POST https://www.strava.com/api/v3/uploads \
    > To check the status of your update, use the `id` from the JSON response and run
    >
    > ```shell
    > curl https://www.strava.com/api/v3/uploads/ID -H "Authorization: Bearer ${STRAVA_ACCESS_TOKEN}"
    > curl https://www.strava.com/api/v3/uploads/ID -H "Authorization: Bearer OAUTH_TOKEN"
    > ```

    If you want to upload a directory with files, use the following command
  2. michaellihs revised this gist May 4, 2022. 1 changed file with 12 additions and 11 deletions.
    23 changes: 12 additions & 11 deletions strava_cli.md
    Original file line number Diff line number Diff line change
    @@ -3,11 +3,10 @@ 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

    > **Run the following steps with your user logged in to Strava in your browser!**
    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 [https://strava.github.io/api/v3/oauth/](https://www.strava.com/settings/api) and create a new API. The settings are as follows:

    * `Application Name` chose whatever name you like (does not matter for our use case)
    @@ -36,13 +35,13 @@ For the purpose of generating the OAuth token, this documentation helps a lot [h
    3. Click "Authorise"
    4. Cope the Code from the URL that is given as the URL `code` parameter
    5. Run the following CURL request, to get the final OAuth token:
    5. Run the following CURL request, to get the final OAuth token (replace `CLIENT_ID`, `CLIENT_SECRET` and `CODE` accordingly):

    ```
    ```shell
    curl -X POST https://www.strava.com/oauth/token \
    -F client_id=12345 \
    -F client_secret=... \
    -F code=...
    -F client_id=CLIENT_ID \
    -F client_secret=CLIENT_SECRET \
    -F code=CODE
    ```

    5. Copy the `access_token` from the JSON response - this is your OAuth token
    @@ -69,9 +68,11 @@ curl -X POST https://www.strava.com/api/v3/uploads \

    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 https://www.strava.com/api/v3/uploads -H "Authorization: Bearer OAUTH_TOKEN" -F file=@"$i" -F data_type="tcx"
    done
    ```shell
    for i in `ls /path/to/files/*.tcx`
    do curl -X POST https://www.strava.com/api/v3/uploads -H "Authorization: Bearer OAUTH_TOKEN" -F file=@"$i" -F data_type="tcx"
    done
    ```


    ## Further References
  3. michaellihs revised this gist May 3, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion strava_cli.md
    Original file line number Diff line number Diff line change
    @@ -35,7 +35,7 @@ For the purpose of generating the OAuth token, this documentation helps a lot [h
    > make sure to properly quote the redirect URL
    3. Click "Authorise"
    4. Cope the Code from the URL that is given as the `code` parameter
    4. Cope the Code from the URL that is given as the URL `code` parameter
    5. Run the following CURL request, to get the final OAuth token:

    ```
  4. michaellihs revised this gist May 3, 2022. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion strava_cli.md
    Original file line number Diff line number Diff line change
    @@ -28,7 +28,9 @@ For the purpose of generating the OAuth token, this documentation helps a lot [h

    1. Open the following URL (replace `CLIENT_ID` with the ID from above):

    ```https://www.strava.com/oauth/authorize?client_id=CLIENT_ID&response_type=code&redirect_uri=http%3A%2F%2Flocalhost&scope=activity:write&state=mystate&approval_prompt=force```
    ```
    https://www.strava.com/oauth/authorize?client_id=CLIENT_ID&response_type=code&redirect_uri=http%3A%2F%2Flocalhost&scope=activity:write&state=mystate&approval_prompt=force
    ```

    > make sure to properly quote the redirect URL
  5. michaellihs revised this gist May 3, 2022. 1 changed file with 9 additions and 4 deletions.
    13 changes: 9 additions & 4 deletions strava_cli.md
    Original file line number Diff line number Diff line change
    @@ -26,10 +26,15 @@ Open the [https://strava.github.io/api/v3/oauth/](https://strava.github.io/api/v

    For the purpose of generating the OAuth token, this documentation helps a lot [https://strava.github.io/api/v3/oauth/](https://strava.github.io/api/v3/oauth/).

    1. Open the following URL (replace `CLIENT_ID` with the ID from above): `https://www.strava.com/oauth/authorize?client_id=CLIENT_ID&response_type=code&redirect_uri=http%3A%2F%2Flocalhost&scope=activity:write&state=mystate&approval_prompt=force` (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:
    1. Open the following URL (replace `CLIENT_ID` with the ID from above):

    ```https://www.strava.com/oauth/authorize?client_id=CLIENT_ID&response_type=code&redirect_uri=http%3A%2F%2Flocalhost&scope=activity:write&state=mystate&approval_prompt=force```

    > make sure to properly quote the redirect URL
    3. Click "Authorise"
    4. Cope the Code from the URL that is given as the `code` parameter
    5. Run the following CURL request, to get the final OAuth token:

    ```
    curl -X POST https://www.strava.com/oauth/token \
  6. michaellihs revised this gist May 3, 2022. 1 changed file with 5 additions and 5 deletions.
    10 changes: 5 additions & 5 deletions strava_cli.md
    Original file line number Diff line number Diff line change
    @@ -54,11 +54,11 @@ curl -X POST https://www.strava.com/api/v3/uploads \
    > other `data_type`s can be
    > `fit`, `fit.gz`, `tcx`, `tcx.gz`, `gpx`, `gpx.gz`
    To check the status of your update, use the `id` from the JSON response and run

    ```shell
    curl https://www.strava.com/api/v3/uploads/ID -H "Authorization: Bearer ${STRAVA_ACCESS_TOKEN}"
    ```
    > To check the status of your update, use the `id` from the JSON response and run
    >
    > ```shell
    > curl https://www.strava.com/api/v3/uploads/ID -H "Authorization: Bearer ${STRAVA_ACCESS_TOKEN}"
    > ```
    If you want to upload a directory with files, use the following command
  7. michaellihs revised this gist May 3, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion strava_cli.md
    Original file line number Diff line number Diff line change
    @@ -52,7 +52,7 @@ curl -X POST https://www.strava.com/api/v3/uploads \
    ```

    > other `data_type`s can be
    > `fit, fit.gz, tcx, tcx.gz, gpx, gpx.gz`
    > `fit`, `fit.gz`, `tcx`, `tcx.gz`, `gpx`, `gpx.gz`
    To check the status of your update, use the `id` from the JSON response and run

  8. michaellihs revised this gist May 3, 2022. 1 changed file with 14 additions and 1 deletion.
    15 changes: 14 additions & 1 deletion strava_cli.md
    Original file line number Diff line number Diff line change
    @@ -45,7 +45,20 @@ For the purpose of generating the OAuth token, this documentation helps a lot [h
    Now comes the funny part. Use the following command to upload a track to Strava:
    curl -X POST https://www.strava.com/api/v3/uploads -H "Authorization: Bearer OAUTH_TOKEN" -F file=@"PATH_TO_FILE" -F data_type="tcx"
    ```shell
    curl -X POST https://www.strava.com/api/v3/uploads \
    -H "Authorization: Bearer OAUTH_TOKEN"
    -F file=@"PATH_TO_FILE" -F data_type="tcx"
    ```

    > other `data_type`s can be
    > `fit, fit.gz, tcx, tcx.gz, gpx, gpx.gz`
    To check the status of your update, use the `id` from the JSON response and run

    ```shell
    curl https://www.strava.com/api/v3/uploads/ID -H "Authorization: Bearer ${STRAVA_ACCESS_TOKEN}"
    ```

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

  9. michaellihs revised this gist May 3, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion strava_cli.md
    Original file line number Diff line number Diff line change
    @@ -26,7 +26,7 @@ Open the [https://strava.github.io/api/v3/oauth/](https://strava.github.io/api/v

    For the purpose of generating the OAuth token, this documentation helps a lot [https://strava.github.io/api/v3/oauth/](https://strava.github.io/api/v3/oauth/).

    1. Open the following URL (replace `CLIENT_ID` with the ID from above): `https://www.strava.com/oauth/authorize?client_id=CLIENT_ID&response_type=code&redirect_uri=http%3A%2F%2Flocalhost&scope=write&state=mystate&approval_prompt=force` (make sure to properly quote the redirect URL)
    1. Open the following URL (replace `CLIENT_ID` with the ID from above): `https://www.strava.com/oauth/authorize?client_id=CLIENT_ID&response_type=code&redirect_uri=http%3A%2F%2Flocalhost&scope=activity:write&state=mystate&approval_prompt=force` (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:
  10. michaellihs created this gist Oct 24, 2017.
    61 changes: 61 additions & 0 deletions strava_cli.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,61 @@
    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 [https://strava.github.io/api/v3/oauth/](https://www.strava.com/settings/api) 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. [http://google.com] (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 [https://strava.github.io/api/v3/oauth/](https://strava.github.io/api/v3/oauth/) 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 [https://strava.github.io/api/v3/oauth/](https://strava.github.io/api/v3/oauth/).

    1. Open the following URL (replace `CLIENT_ID` with the ID from above): `https://www.strava.com/oauth/authorize?client_id=CLIENT_ID&response_type=code&redirect_uri=http%3A%2F%2Flocalhost&scope=write&state=mystate&approval_prompt=force` (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 https://www.strava.com/oauth/token \
    -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 https://www.strava.com/api/v3/uploads -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 https://www.strava.com/api/v3/uploads -H "Authorization: Bearer OAUTH_TOKEN" -F file=@"$i" -F data_type="tcx"
    done
    ## Further References
    * [Strava Documentation for OAuth](https://strava.github.io/api/v3/oauth/#get-authorize)
    * [Python Implementation](https://github.com/mpolla/stravaup)
    * [Runtastic Downloader](https://github.com/Metalnem/runtastic)