Bulk update Strava rides to new sport type "MountainBikeRide" using Strava API? Rate limit

Looks like Strava recently introduced a new “sport type” that includes mountain bike rides. I have several hundreds of rides in Strava which are actually all mountain bike rides. Of course I don’t want to change these manually, so I’m planning to write a JavaScript script that will do this for me using the Strava API and the NodeJS module node-strava-v3.

It took me some time to get a proper access token with the right scope (strava-cli to the rescue!), but I’m now able to update the sports_type of a single activity.

Unfortunately the Strava API has rather strict rate limits: the default rate limit allows 100 requests every 15 minutes, with up to 1,000 requests per day.

How would you handle this rate limit?

Do I need to create a script that updates activities in batches and runs for several hours (waiting most of the time), or can I do something smarter? What?

I don’t know Strava’s API at all, but rate limits are usually set up to slow automations down so they don’t use too much in the way of resources.

My guess is you’ll need to run on a schedule, include enough pauses, etc., to stay within the rate limit.

I don’t know if this is necessarily “smarter”, but I would use a schedule rather than having a script pause and hang around in the background.

I use at for one off jobs, so I would parameterise or read values from a file for the main script, and use another script for or manually create the at commands (depending upon the number of commands required).

1 Like

I’m indeed in doubt between these options.

I wish they offered bulk update (so that I could update an array of activities, instead of a single activity, in a single call).

Since (I hope) I need to run this script only once, I did not want to put too much effort in it, but the reference to the at command was super helpful!

I used this command to “schedule” my script on a Raspberry Pi, so the script would continue to run, even if I accidentally exited the shell that I used to SSH into the Pi. As a bonus, the script could easily read my Strava access token from the environment.

The script initially determines which activities are rides on MTB bikes and then updates batches of 90 rides every 20 minutes (to safely stay within the 100 requests per 15 minutes rate limit)

This worked great. All those rides are now marked as “Mountain Bike Ride” :smile: