Strava API updateActivityById - Resource Not Found Error

33 Views Asked by At

I'm trying to update a Strava activity using the Strava API endpoint updateActivityById with a PUT request in Python. However, I'm consistently getting a "Resource Not Found" error. Here's my code:

def update_acti(idd):
   activity_write_read_all_token = ***

    url = f'https://www.strava.com/api/v3/activities/{idd}'
    
    header = {
        'Content-Type': 'application/json',
        'Authorization': 'Bearer ' + activity_write_read_all_token
        }
    
    data = {
        'gear_id' : user['shoes'] #shoes identifier, string
        }
    
    r = requests.put(url, headers = header, json = data).json()
    return r

response = update_acti(12345678901)

I get an error 404 : Ressource Not Found.

I first checked that the activity existed with getActivityById and it does. The user['shoes'] returns the correct gear id as a string. Even with this line commented I still get the error.

Then I suppose the error comes from my PUT request "syntax" or from the access token.

The endpoint requires an activity:write and activity:read_all scope authorization to access activity no matter the privacy setting. I generated an exchange code for these two scopes with following url and got the access token.

http://www.strava.com/oauth/authorize?client_id={client_id}&response_type=code&redirect_uri=http://localhost/exchange_token&approval_prompt=force&scope=activity:write,read_all

Do you see something I missed or have an idea on what might be causing the problem ? Thanks.

0

There are 0 best solutions below