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 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/ 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/ page again and copy the following values to a text editor
Client ID
- an ID for your application, used later on to identify your AppSecret
- a secret token generated for you (not your OAuth Token!)
For the purpose of generating the OAuth token, this documentation helps a lot https://strava.github.io/api/v3/oauth/.
-
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
-
Click "Authorise"
-
Cope the Code from the URL that is given as the URL
code
parameter -
Run the following CURL request, to get the final OAuth token (replace
CLIENT_ID
,CLIENT_SECRET
andCODE
accordingly):curl -X POST https://www.strava.com/oauth/token \ -F client_id=CLIENT_ID \ -F client_secret=CLIENT_SECRET \ -F code=CODE
-
Copy the
access_token
from the JSON response - this is your OAuth token
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"
other
data_type
s can befit
,fit.gz
,tcx
,tcx.gz
,gpx
,gpx.gz
To check the status of your update, use the
id
from the JSON response and runcurl 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
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
With Strava rate limiting https://developers.strava.com/docs/rate-limits/.
I had to add
sleep 6