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.
References
Generate an API Key
Strava uses OAuth2 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. To create a new API, go to https://www.strava.com/settings/api. The settings are as follows:
Application Name
choose whatever name you likeWebsite
choose whatever website you want to use (needs to be a valid url]Callback Domain
any domain name that should be used as a callback
After you saved your API, you need to upload a image for it.
Then, copy the following values to use for HTTP requests.
Client ID
- an ID for your application, used later on to identify your AppSecret
- a secret token generated for you (not your OAuth Token!)
Generate an OAuth Token
Strava has defined seven different types of permissions to access the API:
- read
- read_all
- profile:read_all
- profile:write
- activity:read
- activity:read_all
- activity:write
Please refer to the official documentation for what each scope represent.
- Open the following URL (replace CLIENT_ID with the ID from above):
|
|
- Login to Strava then click
Authorize
and tick the required permissions if needed. - Browser should go to 404 as
http://localhost/exchange_token
doesn’t exist. - Copy the authorization code from 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):
|
|
- Copy the
access_token
from the JSON response - this is your OAuth token
|
|
Get Authenticated Athlete
Returns the currently authenticated athlete. Tokens with profile:read_all
scope will receive a detailed athlete representation; all others will receive a summary representation.
|
|
Upload the tracks
Use the following command to upload a track to Strava:
|
|
The other data_types 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
|
|
If you want to upload a directory with files, use the following command
|
|