Skip to main content

Wondering if someone could help - I'm trying to obtain totals for an athlete.  I have managed to get all activities, but would also like totals.

This is the following code I am using:

stats_url = f"https://www.strava.com/api/v3/athletes/{client_id}/stats?" f"access_token={access_token}" statsresponse = requests.get(stats_url) stats = statsresponse.json() print('Stats API:', stats_url) ride_total_year_calculated = round(stats['ytd_ride_totals']['distance']/1000,1 )

 

When copy and pasting the URL I get the following response:

 

{"message":"Forbidden","errors":[]}


 I'm obviously doing something really stupid here, but can't see it right now!

 

For further info, the following works:

activities_url = f"https://www.strava.com/api/v3/athlete/activities?" f"access_token={access_token}" print('RESTful API:', activities_url) response = requests.get(activities_url, params=params) print(len(response.json())) for i in range(0,len(response.json())): activity = response.json()[i] print('Disance:', activity['distance'], 'm') print('Date:', activity['start_date']) print('type:', activity['type'])

 

stats_url = f"https://www.strava.com/api/v3/athletes/{client_id}/stats?" 
            f"access_token={access_token}"

Did you mean to insert client_id there? That should be athlete_id

See: https://developers.strava.com/docs/reference/#api-Athletes-getStats

GET /athletes/{id}/stats

Parameters

id
required Long, in path
The identifier of the athlete. Must match the authenticated athlete.

 


That's a good point - however that is set to my athlete ID.  The URL looks like this (with x's as actual athlete id):

 

https://www.strava.com/api/v3/athletes/xxxxxx/stats?access_token=2ac758f65d08641b17791d6c69ed1a708407b1ca


You’re absolutely right, thank you so much