@@ -28,15 +28,96 @@ easier to find based on the official documentation.
2828
2929## Inconsistencies in the API
3030
31- The Fitbit API contains several inconsistencies, which our method names
32- necessarily reflect:
31+ The Fitbit API contains several inconsistencies, which our method names and
32+ implementation necessarily reflect. Understanding these inconsistencies can help
33+ you navigate the API more effectively:
3334
34- - ` create_activity_goals ` creates only one goal at a time
35+ ### Method Name vs. Functionality Inconsistencies
36+
37+ - ` create_activity_goals ` creates only one goal at a time, despite the plural
38+ name
3539- ` add_favorite_foods ` adds one food at a time, while all other creation methods
3640 use "create" prefix
41+ - ` get_sleep_goals ` returns a single goal, not multiple goals
3742- Some pluralized methods return lists, while others return dictionaries
3843 containing lists
3944
45+ ### Parameter and Response Format Inconsistencies
46+
47+ ``` python
48+ # Sleep endpoint uses a different API version than most other endpoints
49+ client.sleep.get_sleep_log_by_date(date = " 2025-01-01" ) # Uses API v1.2
50+ client.activity.get_daily_activity_summary(date = " 2025-01-01" ) # Uses API v1
51+
52+ # Sleep date parameters have inconsistent response behavior
53+ # The request uses "2025-01-01" but response might contain data from "2025-01-02"
54+ sleep_data = client.get_sleep_log_by_date(date = " 2025-01-01" )
55+ # A sleep log started on 2025-01-01 at 23:00 and ended on 2025-01-02 at 07:00
56+ # will be included in the response, but with dateOfSleep="2025-01-02"
57+
58+ # Pagination parameters vary across endpoints
59+ # Some endpoints require offset=0
60+ food_log = client.get_food_log(date = " 2025-01-01" , offset = 0 ) # Valid
61+ # Others support arbitrary offsets
62+ badges = client.get_badges(offset = 20 ) # Also valid
63+
64+ # Date range validations vary by endpoint
65+ # Sleep endpoints allow up to 100 days
66+ sleep_logs = client.get_sleep_log_by_date_range(
67+ start_date = " 2025-01-01" ,
68+ end_date = " 2025-04-10" # 100 days later, valid for sleep endpoint
69+ )
70+ # Activity endpoints allow only 31 days
71+ activity_logs = client.get_activity_log_list(
72+ before_date = " 2025-02-01" ,
73+ after_date = " 2025-01-01" # 31 days earlier, valid for activity endpoint
74+ )
75+ ```
76+
77+ ### Response Structure Inconsistencies
78+
79+ The structure of API responses varies widely across endpoints:
80+
81+ ``` python
82+ # Some endpoints return arrays directly
83+ activities = client.get_frequent_activities()
84+ # activities is a List[Dict[str, Any]] (array of activity objects)
85+
86+ # Others wrap arrays in a parent object with a named property
87+ sleep_logs = client.get_sleep_log_by_date(date = " 2025-01-01" )
88+ # sleep_logs is a Dict[str, Any] with a "sleep" property containing the array
89+
90+ # Some endpoints use plural property names for lists
91+ weight_logs = client.get_weight_logs(date = " 2025-01-01" )
92+ # weight_logs["weight"] is the list of weight logs
93+
94+ # Others use singular property names for lists
95+ food_logs = client.get_food_log(date = " 2025-01-01" )
96+ # food_logs["foods"] is the list of food logs
97+ ```
98+
99+ ### Error Response Inconsistencies
100+
101+ Error responses can also vary in structure:
102+
103+ ``` python
104+ try :
105+ # Some validation errors include field names
106+ client.create_food_log(food_id = " invalid" , amount = 100 , meal_type_id = 1 )
107+ except ValidationException as e:
108+ print (e.field_name) # Might be "foodId"
109+
110+ try :
111+ # Other validation errors omit field names
112+ client.get_activity_tcx(log_id = " invalid" )
113+ except InvalidRequestException as e:
114+ print (e.field_name) # Might be None
115+ ```
116+
117+ Our library handles these inconsistencies internally to provide a unified
118+ experience, but it's helpful to be aware of them when working with the raw API
119+ responses.
120+
40121## Method Aliases
41122
42123For user convenience, some methods have aliases:
0 commit comments