2

In my application I'm making API calls to fetch Fitbit data of a user,when I make an API call to "Get Daily Activity Summary" I get empty activities array.

I'm getting everything from this API call just activities array is coming out as empty[]. Below is the sample response of API call.

{  
   "activities":[  

   ],
   "goals":{  
      "caloriesOut":2826,
      "distance":8.05,
      "floors":150,
      "steps":10000
   },
   "summary":{  
      "activityCalories":230,
      "caloriesBMR":1913,
      "caloriesOut":2143,
      "distances":[  
         {  
            "activity":"tracker",
            "distance":1.32
         },
         {  
            "activity":"loggedActivities",
            "distance":0
         },
         {  
            "activity":"total",
            "distance":1.32
         },
         {  
            "activity":"veryActive",
            "distance":0.51
         },
         {  
            "activity":"moderatelyActive",
            "distance":0.51
         },
         {  
            "activity":"lightlyActive",
            "distance":0.51
         },
         {  
            "activity":"sedentaryActive",
            "distance":0.51
         },
         {  
            "activity":"Treadmill, 0% Incline",
            "distance":3.28
         }
      ],
      "elevation":48.77,
      "fairlyActiveMinutes":0,
      "floors":16,
      "lightlyActiveMinutes":0,
      "marginalCalories":200,
      "sedentaryMinutes":1166,
      "steps":0,
      "veryActiveMinutes":0
   }
}
Saadi
  • 2,211
  • 4
  • 21
  • 50
NewbieCoder
  • 377
  • 3
  • 16
  • Your json is having empty `"activities":[ ]`. That's why it's emptied. You might have something wrong while calling the API. – Saadi Dec 19 '16 at 10:28
  • That's what I'm saying @Saadi. After making an API call I 'm getting an empty activites array, everything is coming properly just not getting values in "activities" array. – NewbieCoder Dec 19 '16 at 10:30
  • There is something wrong in your call/issue in web api. I can't judge it. – Saadi Dec 19 '16 at 10:48

2 Answers2

1

We can log the activities in two ways.

  1. Log into fitbit portal (https://www.fitbit.com/) and manually log one activity.
  2. Sync your fitbit device with your application (android or Iphone).

In First Case, you will get the activities collection, when you request for that day for which you have logged the activity.

Suppose you have logged an activity for 18th Dec 2016.

Request Url : https://api.fitbit.com/1/user/-/activities/date/2016-12-18.json

Response:

{
  "activities": [
    {
      "activityId": 12030,
      "activityParentId": 90009,
      "activityParentName": "Run",
      "calories": 530,
      "description": "Running - 5 mph (12 min/mile)",
      "distance": 1,
      "duration": 3600000,
      "hasStartTime": true,
      "isFavorite": false,
      "lastModified": "2016-12-19T12:07:51.124Z",
      "logId": 5218814487,
      "name": "Run",
      "startDate": "2016-12-18",
      "startTime": "06:00",
      "steps": 843
    }
  ],
  "goals": {
    "activeMinutes": 30,
    "caloriesOut": 2689,
    "distance": 8.05,
    "steps": 10000
  },
  "summary": {
    "activeScore": -1,
    "activityCalories": 1658,
    "caloriesBMR": 1588,
    "caloriesOut": 2927,
    "distances": [
      {
        "activity": "Run",
        "distance": 1
      },
      {
        "activity": "total",
        "distance": 7.42
      },
      {
        "activity": "tracker",
        "distance": 7.1
      },
      {
        "activity": "loggedActivities",
        "distance": 1
      },
      {
        "activity": "veryActive",
        "distance": 1.99
      },
      {
        "activity": "moderatelyActive",
        "distance": 0.03
      },
      {
        "activity": "lightlyActive",
        "distance": 5.41
      },
      {
        "activity": "sedentaryActive",
        "distance": 0
      }
    ],
    "fairlyActiveMinutes": 1,
    "lightlyActiveMinutes": 297,
    "marginalCalories": 961,
    "sedentaryMinutes": 108,
    "steps": 9982,
    "veryActiveMinutes": 74
  }
}

In Second Case, where you have fitbit activity tracker, you will not get activities collection for data logged thenter code here`rough fitbit band. You can check that data in fitbit portal. That will be logged as activity record.

But you will get the summary section. where you will find useful information needed. Like Steps, calorie burned etc. So always use summary section in place of activities collection.

In your case, you have not logged any activity that's why you are not getting any activities collection. Apart from activities collection , the data that you are getting is default data that we get even when there is no activity for that day.

Manav
  • 160
  • 8
  • I'm having Fitbit application in my iPhone and have mobile synced so I don't need to log activity. In my C# application I'm just making an API call to "Fetch Activity" and getting empty array of "activities" in response. I hope you understand. – NewbieCoder Dec 23 '16 at 06:26
  • For data synced through device, we will get "empty activities". Data logged through device is not logged as a particular activity, for example walking, running etc. So, we will not get "activities" collection. We should use summary object to get information like steps, calorie burned, distance etc. – Manav Dec 23 '16 at 10:34
  • Thanks @Manav. Appreciate your help. Is there any reference to this? – NewbieCoder Dec 23 '16 at 11:14
  • I verified this while integrating fitbit with our app in my organization. We bought a device for this integration. We found the above mentioned behavior and this is working fine. – Manav Dec 23 '16 at 12:23
  • Ok, Thanks for the help Manav. – NewbieCoder Dec 23 '16 at 13:07
0

Try this:

It will give the activity list as Fitbit displays in their website.

https://api.fitbit.com/1/user/{fitbit-user-id}/activities/list.json?beforeDate=2017-09-29&sort=desc&offset=0&limit=20

Rohit Dhiman
  • 131
  • 1
  • 4