Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Retrieve Historical Data

ANSWERED

Looking for best practice for retrieving historical data.

 

For example, I want to retrieve that last 30 days of activities for a user. It seems I would have to make several requests:

https://api.fitbit.com/1/user/-/activities/date/2021-09-13.json
https://api.fitbit.com/1/user/-/activities/date/2021-09-12.json
https://api.fitbit.com/1/user/-/activities/date/2021-09-11.json
https://api.fitbit.com/1/user/-/activities/date/2021-09-10.json
... 25 more ...
https://api.fitbit.com/1/user/-/activities/date/2021-08-14.json

Is there a way to combine those requests and get both activities and summary data for each day?

I have looked at the other requests available in the docs, but don't see any others that return the summary nodes.

 

Reason for question: we are hitting rate limit for a user when we "refresh" their data or when they first connect to our app and we want to retrieve historical data.

30 days * 5 message types (activities, foods, body, sleep, heart rate)

 

Thanks!

 

Best Answer
0 Votes
1 BEST ANSWER

Accepted Solutions

Hi @Jeff_New_Ocean 

 

We do have some information on querying historical data located in our Developer Guide.   See Querying Historical Data.

 

Depending on what data you need, you'll need to use a mix of the summary and the time series endpoints.  For example, with activity you're currently executing 30 API calls to get the activities and summary data.   You can execute the Get Activity Log List endpoint to query all the activities for a specific date range.   For the summary data, you can call the activity time series endpoint, specifying a month long date range, and change the resource to query.   We support 11 resources.   This could reduce the number of API calls from 30 to 12 (1 activity log list + 11 activity time series)

 

The link to the activity endpoints mentioned are

Activity Log List: https://dev.fitbit.com/build/reference/web-api/activity/#get-activity-logs-list

 

We have time series endpoints for food, body, sleep and heart rate.   You should be able to query a months worth of data for each of these in a single API call.

 

Let us know if you need more information on this.

 

Best,

Gordon

Activity Time Series: https://dev.fitbit.com/build/reference/web-api/activity/#activity-time-series

Gordon Crenshaw
Senior Technical Solutions Consultant
Fitbit Partner Engineering & Web API Support | Google

View best answer in original post

Best Answer
2 REPLIES 2

Hi @Jeff_New_Ocean 

 

We do have some information on querying historical data located in our Developer Guide.   See Querying Historical Data.

 

Depending on what data you need, you'll need to use a mix of the summary and the time series endpoints.  For example, with activity you're currently executing 30 API calls to get the activities and summary data.   You can execute the Get Activity Log List endpoint to query all the activities for a specific date range.   For the summary data, you can call the activity time series endpoint, specifying a month long date range, and change the resource to query.   We support 11 resources.   This could reduce the number of API calls from 30 to 12 (1 activity log list + 11 activity time series)

 

The link to the activity endpoints mentioned are

Activity Log List: https://dev.fitbit.com/build/reference/web-api/activity/#get-activity-logs-list

 

We have time series endpoints for food, body, sleep and heart rate.   You should be able to query a months worth of data for each of these in a single API call.

 

Let us know if you need more information on this.

 

Best,

Gordon

Activity Time Series: https://dev.fitbit.com/build/reference/web-api/activity/#activity-time-series

Gordon Crenshaw
Senior Technical Solutions Consultant
Fitbit Partner Engineering & Web API Support | Google
Best Answer

Hi @Gordon-C

We were wondering if there is any provision for requesting a higher rate limit to handle these scenarios. We have some cases where we may want to retrieve up to 180 days worth of historical data. Nothing crazy, may up to 300 / user / hour? Just thought I'd ask about the possibility.

In the meantime I'll look at reducing the number of requests based your last reply. But I feel like even with the per measure date range requests combined with the per day requests required to retrieve the summary nodes on the activity messages (for routine data) and food messages (for water), we will approach and possible exceed 150.

Thanks!

Best Answer
0 Votes