Upload workouts to Strava
planned (tbd)
Quinn Comendant
I like to upload my workouts to Strava. I usually track workouts using the WorkOutDoors AW app, which offers an “Upload to Strava” button after ending a workout. It's simple and works well. This is low priority, but it would be nice to have someday.
Strava has a nice API, easy to use:
- Authenticate via oAuth flow to get a persistant token (just once).
- Upload workouts using the Upload Activity API endpoint.
Here's instructions from ChatGPT for implementing this in Swift:
To upload a workout with timeseries heart rate data to Strava, you'll need to create a file in a supported format (e.g., .FIT, .TCX, or .GPX) that includes the heart rate data. Here, we'll focus on creating a .TCX (Training Center XML) file, as it's a common format for such data. After creating the file, you'll use the Strava API's "Upload Activity" endpoint to upload this file.
### Step 1: Create a .TCX File
You need to create a .TCX file that includes your timeseries heart rate data. A simplified .TCX example with heart rate data might look like this:
<?xml version="1.0" encoding="UTF-8"?>
<TrainingCenterDatabase xmlns="http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v2">
<Activities>
<Activity Sport="WeightTraining">
<Id>2024-02-21T09:00:00Z</Id>
<Lap StartTime="2024-02-21T09:00:00Z">
<TotalTimeSeconds>3600</TotalTimeSeconds>
<Track>
<Trackpoint>
<Time>2024-02-21T09:00:00Z</Time>
<HeartRateBpm>
<Value>120</Value>
</HeartRateBpm>
</Trackpoint>
<!-- Add more Trackpoint entries here with respective times and heart rates -->
</Track>
</Lap>
</Activity>
</Activities>
</TrainingCenterDatabase>
### Step 2: Upload the .TCX File Using Strava API
After creating your .TCX file, you'll use the Strava API's "Upload Activity" endpoint to upload the file. Here's how you can do it in Swift, using
URLSession
for the network request:import Foundation
let token = "YOUR_ACCESS_TOKEN" // Replace with your actual access token
let url = URL(string: "https://www.strava.com/api/v3/uploads")!
var request = URLRequest(url: url)
request.httpMethod = "POST"
let boundary = "Boundary-\(UUID().uuidString)"
request.setValue("multipart/form-data; boundary=\(boundary)", forHTTPHeaderField: "Content-Type")
request.setValue("Bearer \(token)", forHTTPHeaderField: "Authorization")
let fileURL = URL(fileURLWithPath: "path/to/your/file.tcx") // Path to your .TCX file
let fileName = "workout.tcx"
var body = Data()
body.append("--\(boundary)\r\n".data(using: .utf8)!)
body.append("Content-Disposition: form-data; name=\"file\"; filename=\"\(fileName)\"\r\n".data(using: .utf8)!)
body.append("Content-Type: application/octet-stream\r\n\r\n".data(using: .utf8)!)
body.append(try! Data(contentsOf: fileURL))
body.append("\r\n".data(using: .utf8)!)
body.append("--\(boundary)--\r\n".data(using: .utf8)!)
request.httpBody = body
let session = URLSession.shared
let task = session.dataTask(with: request) { data, response, error in
if let error = error {
print("Error: \(error)")
return
}
if let data = data, let dataString = String(data: data, encoding: .utf8) {
print("Response data: \(dataString)")
}
}
task.resume()
This Swift code constructs a multipart/form-data request to upload your .TCX file to Strava. Make sure to replace
"YOUR_ACCESS_TOKEN"
with your actual access token and "path/to/your/file.tcx"
with the path to your .TCX file.After uploading, Strava processes the file and creates the activity, including the timeseries heart rate data.
Amanda
Merged in a post:
Connect to Strava
S
Serge De Vos
When can we connect strength workouts to Strava ?
Amanda
Merged in a post:
Strava support
Raphael Stella
I and many other friends of mine would love to see Strava support for strength training, now we love the overall look and feel of bevel strength training on the Apple Watch. The only thing keeping us away from using it that we track our workouts on strava
Amanda
Merged in a post:
Automatic Uploads of strength workouts to Strava
L
Leandro Giovando
A while ago Strava disabled the ability to upload 3rd party app workouts via the Apple Health App onto their platform. It's a shame and typical of them. I was wondering if there was a way for Bevel to integrate with them or some work around to automatically upload a strength session to Strava.
Amanda
Hi Leandro Giovando, this is a common ask, and it is on our roadmap to add an integration to Strava!
J
Jenni Alley
What might be the ETA on this feature?
Quinn Comendant
In the meantime, I can recommend the HealthFit app for uploading to Strava, and myriad other fitness analytics platforms like Runalyze, TrainingPeaks, et al. It's loaded with nerdy metrics. I'm also using to track running shoes and cycling drivetrain lifespan. 🤓
Grey
planned (tbd)
Adam Frost
This is definitely in my top 10. I use Strava for many many reasons, and if I can’t upload easily to there, I can’t use the otherwise really great strength training feature recently added.
Rory Plewes
Adam Frost You can use something like health fit or rungap to push workouts from apple heath to strava or vice versa.
Grey
planned (soon)
Grey
Thanks Quinn Comendant for the feedback and implementation suggestion.
It should not be hard to build, but as you said, this is probably on the lower end of my priority list. I'll add it to the roadmap regardless, and maybe I can squeeze it in with one of the updates.
Load More
→