cyberjunky / python-garminconnect

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

Feature Request: Generic API Calls #228

Open linuxlurak opened 1 month ago

linuxlurak commented 1 month ago

Hi,

What do you think of the idea of having some kind of generic API call option? This would allow me to do weigh-ins with date, for example. The call on the garmin connect website is like this:

{
    ‘POST": {
        "scheme": “https”,
        "host": “connect.garmin.com”,
        "filename": “/weight-service/user-weight”,
        "remote": {
            "address": "104.17.168.14:443’
        }
    }
}

Payload:

{
    "dateTimestamp": “2024-10-05T16:04:00.00”,
    "gmtTimestamp": “2024-10-05T14:04:00.00”,
    "unitKey": “kg”,
    "value": 100
}

The remote part in the POST is most likely not necessary.

linuxlurak commented 1 month ago

Another idea would be to move these API definitions to an external file so that the community can react more quickly to changes. Systematic monitoring might even be conceivable.

psdupvi commented 1 month ago

I think there is already the connectapi method

    def connectapi(self, path, **kwargs):
        return self.garth.connectapi(path, **kwargs)

There are some examples of its usage to POST in add_body_composition and add_weigh_in, and I think it actually serves as the requester for all the get_ endpoints. There's also a PUT for add_hydration_data

It's not particularly well documented here, since it's technically a garth method:

    def connectapi(self, path: str, method="GET", **kwargs):
        resp = self.request(method, "connectapi", path, api=True, **kwargs)
        if resp.status_code == 204:
            rv = None
        else:
            rv = resp.json()
        return rv

I think this should roughly allow what you want, although it's not a bad idea to add some more formal documentation. I don't necessarily think it's worth adding our own version of the method here, since then we're just duplicating work