cyberjunky / python-garminconnect

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

Steps data not working #168

Closed Gishan86 closed 1 year ago

Gishan86 commented 1 year ago

Hi, did Garmin change the url for steps data? Neither one of these work:

json = api.get_daily_steps("2023-01-01", "2023-10-01") Throws garth.exc.GarthHTTPError: Error in request: 400 Client Error: Bad Request for url: https://connectapi.garmin.com/usersummary-service/stats/steps/daily/2023-01-01/2023-10-01

json = api.get_steps_data("2023-10-17") Returns an empty list.

On https://connect.garmin.com there is step data for 2023-10-17. Other routes like get_weigh_ins work and return data.

Python 3.12
garminconnect==0.2.8
garth==0.4.38
matin commented 1 year ago
  1. iirc, there's a 28-day limit for the date period
  2. 2023-10-17 is currently in the future. No result is correct
Gishan86 commented 1 year ago

Thanks for your quick response!

  1. I've also tried 2022-10-15 to 2022-10-20 and 2023-10-01 to 2023-10-05 which both resulted in the same exception

  2. Yeah, that was a typo, not a time traveller. :) With 2022-10-18 I get results but they are all empty. It returns an empty entry for every 15 minutes of the day like this:

[{'startGMT': '2022-10-17T22:00:00.0', 'endGMT': '2022-10-17T22:15:00.0', 'steps': 0, 'pushes': 0, 'primaryActivityLevel': 'none', 'activityLevelConstant': True}, {'startGMT': '2022-10-17T22:15:00.0', 'endGMT': '2022-10-17T22:30:00.0', 'steps': 0, 'pushes': 0, 'primaryActivityLevel': 'none', 'activityLevelConstant': True}, {'startGMT': '2022-10-17T22:30:00.0', 'endGMT': '2022-10-17T22:45:00.0', 'steps': 0, 'pushes': 0, 'primaryActivityLevel': 'none', 'activityLevelConstant': True}, {'startGMT': '2022-10-17T22:45:00.0', 'endGMT': '2022-10-17T23:00:00.0', 'steps': 0, 'pushes': 0, 'primaryActivityLevel': 'none', 'activityLevelConstant': True}, {'startGMT': '2022-10-17T23:00:00.0', 'endGMT': '2022-10-17T23:15:00.0', 'steps': 0, 'pushes': 0, 'primaryActivityLevel': 'none', 'activityLevelConstant': True}, {'startGMT': '2022-10-17T23:15:00.0', 'endGMT': '2022-10-17T23:30:00.0', 'steps': 0, 'pushes': 0, 'primaryActivityLevel': 'none', 'activityLevelConstant': True}, {'startGMT': '2022-10-17T23:30:00.0', 'endGMT': '2022-10-17T23:45:00.0', 'steps': 0, 'pushes': 0, 'primaryActivityLevel': 'none', 'activityLevelConstant': True}, {'startGMT': '2022-10-17T23:45:00.0', 'endGMT': '2022-10-18T00:00:00.0', 'steps': 0, 'pushes': 0, 'primaryActivityLevel': 'none', 'activityLevelConstant': True}, {'startGMT': '2022-10-18T00:00:00.0', 'endGMT': '2022-10-18T00:15:00.0', 'steps': 0, 'pushes': 0, 'primaryActivityLevel': 'none', 'activityLevelConstant': True}, {'startGMT': '2022-10-18T00:15:00.0', 'endGMT': '2022-10-18T00:30:00.0', 'steps': 0, 'pushes': 0, 'primaryActivityLevel': 'none', 'activityLevelConstant': True}, {'startGMT': '2022-10-18T00:30:00.0', 'endGMT': '2022-10-18T00:45:00.0', 'steps': 0, 'pushes': 0, 'primaryActivityLevel': 'none', 'activityLevelConstant': True}, {'startGMT': '2022-10-18T00:45:00.0', 'endGMT': '2022-10-18T01:00:00.0', 'steps': 0, 'pushes': 0, 'primaryActivityLevel': 'none', 'activityLevelConstant': True}, {'startGMT': '2022-10-18T01:00:00.0', 'endGMT': '2022-10-18T01:15:00.0', 'steps': 0, 'pushes': 0, 'primaryActivityLevel': 'none', 'activityLevelConstant': True}, {'startGMT': '2022-10-18T01:15:00.0', 'endGMT': '2022-10-18T01:30:00.0', 'steps': 0, 'pushes': 0, 'primaryActivityLevel': 'none', 'activityLevelConstant': True}, ...]

The web UI shows 17.843 steps for 2022-10-18 though.

matin commented 1 year ago

I have the same issue for 2022-10-18. Can you try a more recent date like 2023-10-01?

matin commented 1 year ago

weekly works though:

api.garth.connectapi('/usersummary-service/stats/steps/weekly/2022-10-18/52')
matin commented 1 year ago

daily also works for me:

api.get_daily_steps('2022-10-01', '2022-10-28')

It looks like the issue is when you want to get the granular data for an individual day.

matin commented 1 year ago

Figured it out ...

Take a look at this: IMG_4340

You can do the following:

  1. Request Garmin loads the old data:
    resp = api.garth.post('connectapi', '/wellness-service/wellness/epoch/request/2022-10-18', api=True)
    resp.json()

Response:

{'userProfilePk': 2591602,
 'calendarDate': '2022-10-18',
 'status': 'SUBMITTED',
 'source': 'USER',
 'ghReloadMetaData': '',
 'createDate': '2023-10-16T17:49:56.980',
 'deviceList': [{'deviceId': 3329978681,
   'deviceName': 'fēnix® 6X - Pro and Sapphire Editions',
   'preferredActivityTracker': True}]}
  1. Wait a few minutes for the data to load

  2. Make the request again

api.get_steps_data("2022-10-18")

In other words, this is not a garminconnect or Garth issue. It has to do with how Garmin handles old data.

This issue can be closed as it has instructions to:

  1. request weekly steps
  2. request daily steps
  3. request Garmin load old step data and then request that granular data

HTH!

matin commented 1 year ago

@cyberjunky not sure if you want to add the following endpoint:

api.garth.post('connectapi', '/wellness-service/wellness/epoch/request/2022-10-18', api=True)

See the conversation above for context on what it does.

Gishan86 commented 1 year ago

Thanks, would appreciate if the endpoint could be added

cyberjunky commented 1 year ago

Lets keep open so I won't forget to add it ;)

cyberjunky commented 1 year ago

@cyberjunky not sure if you want to add the following endpoint:

api.garth.post('connectapi', '/wellness-service/wellness/epoch/request/2022-10-18', api=True)

See the conversation above for context on what it does @matin Can you enlighten me, didn't follow whole issue... Do I need to add this fixed endpoint with 2022-10-18 at the end?

matin commented 1 year ago

@cyberjunky created the PR #174 with tests

Here's how it works:

def test_request_reload(garmin):
    garmin.login()
    cdate = "2021-01-01"
    assert sum(steps['steps'] for steps in garmin.get_steps_data(cdate)) == 0
    assert garmin.request_reload(cdate)
    # In practice, the data can take a while to load
    assert sum(steps['steps'] for steps in garmin.get_steps_data(cdate)) > 0