Note: a longer example using the standard authentication flows is coming.
First, create an authentication token with the API console:
>>> POST /tokens {permissions: 'all'}
{ "timestamp": 1374137385, "token": "s95kJG3aZJiYaLNaciFvpMQ5ifJ9owih", "user_id": 3287232, "type": "user", "permissions": [ "all" ] }
Next, create the following Python program uploader.py
:
import sys
import requests
token = 's95kJG3aZJiYaLNaciFvpMQ5ifJ9owih'
file_name = sys.argv[1]
file_format = file_name.split('.')[-1]
response = requests.post(
'https://www.cyclinganalytics.com/api/me/rides',
headers={'Authorization': 'Bearer ' + token},
data={'format': file_format},
files={'data': open(file_name)}
)
j = response.json()
print 'Uploaded %s' % j['title']
print 'https://www.cyclinganalytics.com/ride/%s' % j['id']
This uses the excellent Requests library, so you’ll need to have that installed.
Run this, giving a ride file name as the first argument, and the ride will be uploaded:
$ python uploader.py 2012-07-24-11-51-54.fit
Uploaded 100km around Richmond
https://www.cyclinganalytics.com/ride/759597928890
If you have an authentication token and a ride file named 2012-07-24-11-51-54.fit
, the following cURL command will upload the ride and display the JSON returned:
$ curl -X POST -F "format=fit" -F "data=@2012-07-24-11-51-54.fit" --header "Authorization: Bearer s95kJG3aZJiYaLNaciFvpMQ5ifJ9owih" --compressed https://www.cyclinganalytics.com/api/me/rides
{
"trainer": false,
"user_id": 3287232,
"format": "fit",
"notes": "",
"title": "100km around Richmond",
"summary": {
"load": 237,
"distance": 100.326,
"avg_power": 201,
"max_cadence": 121,
"epower": 239,
"avg_speed": 30.890660280533695,
"work": 2538,
"avg_heartrate": 146,
"avg_cadence": 80,
"zones": {
"heartrate": [
337,
2502,
9686,
38,
0
],
"power": [
3116,
1934,
3089,
2634,
887,
814,
89
]
},
"intensity": 85.45958865210116,
"max_speed": 45.3,
"max_power": 1129,
"trimp": 319,
"duration": 12563,
"climbing": 377,
"max_heartrate": 165,
"riding_time": 11692
},
"local_datetime": "2012-07-24T11:51:54",
"utc_datetime": "2012-07-24T01:51:54",
"has": {
"heartrate": true,
"elevation": true,
"temperature": true,
"power": true,
"speed": true,
"cadence": true,
"gps": true
},
"id": 705665962414
}