Upload workouts to Strava
planned (soon)
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
marked this post as
planned (soon)
Amanda
Merged in a post:
Strava integration
S
Samuel
Strength training doesn’t link to Strava. 
Other apps like Hevy can do this!
Amanda
Merged in a post:
Strava Integration
pascal peña
Like Hevy!
Amanda
Merged in a post:
Send workouts to Strava
S
Samuel
Strength training doesn’t link to Strava. 
Other apps like Hevy can do this!
pascal peña
Yess we need strava support!
pascal peña
Yes, If this feature is implemented it would be one app for everything!
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!
Load More
→
