cyberjunky / python-garminconnect

Python 3 API wrapper for Garmin Connect to get activity statistics
MIT License
802 stars 132 forks source link

Change the activity name #172

Closed polcar closed 8 months ago

polcar commented 8 months ago

Hi,

I try to extend API to modify the name of an activity:

url = f"{self.garmin_connect_activity}/{activity_id}"
payload = {"activityId": activity_id, "activityName": title}
return self.garth.post("connect", url, json=payload)

I must add x-http-method-override: PUT to headers to avoid 400 as HTTP status code. But now I am endig with:

ERROR:__main__:Error in request: 401 Client Error: Unauthorized for url: https://connect.garmin.com/activity-service/activity/<ACTIVITY_ID>

When I use the Bearer token from Chrome session in authorization header, I am able to change an activity name. It looks like the authentication must me improved, I am correct?

matin commented 8 months ago

Garth already has a PUT method.

You should be doing the following:

self.garth.put("connectapi", url, json=payload, api=True)

There's an example in the tests to update heart rate zones.

HTH

polcar commented 8 months ago

It works. Thanke you very much.

cyberjunky commented 8 months ago

@polcar I will add this to new version as set_activity_name(id, name)