Strava Automation
Every morning I bike to work, upload the ride to Strava, and then manually toggle the “commute” flag. It’s a small thing, but doing it twice a day, every day, gets old. So I built a small server that does it for me.
The setup
Strava’s API supports webhooks: whenever you upload a new activity, it sends a POST request to a URL of your choice. I wrote a Vapor server in Swift that receives these webhooks, checks whether the activity matches my commute criteria, and if so, updates it via the Strava API.
The flow is straightforward:
- Webhook arrives: Strava notifies the server about a new activity upload
- Fetch details: the server pulls the full activity data from the Strava API
- Evaluate: check whether it matches the commute criteria (route, time of day, activity type)
- Update: if it’s a commute, flip the flag via the API
- Name: generate a descriptive activity name using OpenAI’s GPT-4o mini, based on the route, activity data, and current weather, so rides don’t just show up as “Morning Ride” or “Afternoon Ride”
The stack
The server is built with Vapor, Swift’s most established server-side framework. API types are generated with Swift OpenAPI Generator, which gives you type-safe request and response models straight from the Strava API spec. Fluent handles persistence for keeping track of processed activities.