The Hub is now in read-only mode as we make improvements to the Hub experience. More information is available here.
03-19-2024 08:27 AM - edited 03-19-2024 08:28 AM
Hi,
I'm trying to update an activity using the 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(***)
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 supposed the error came from my PUT request "syntax" or from the access token. So I tested the updateActivityById endpoint using the Swagger Playground. Considering the scope issue in the playground I used a public activity requiring only the activity:write scope. And once again I got a 404 : Ressource Not Found.
I am all out of ideas to solve this so if you have a clue on what could be the problem on my part or if it could be a bug on the endpoint, I'd be glad to hear it. Thanks.
07-25-2024 04:49 PM
I don't know anything about Python, but shouldn't there be a command where the placeholder {idd} is replaced by the activity id?
07-25-2024 04:53 PM
This display isn't showing the formatting, but they are using an f string. The variable name surrounded by brackets will replace that part of the string with the idd variable. https://www.geeksforgeeks.org/formatted-string-literals-f-strings-python/
07-25-2024 04:07 PM
Not sure if you're still seeing this problem, but I was as well. I was able to solve it by simply adding gear_id into the body of the Create Activity call (which is weird since the API does not list that as a valid option for that endpoint... but it works)
Welcome to the Community - here is your guide to help you get started!