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

Not getting Nutritional Information for all foods with api call

I have logged the following lunch foods:

FoodLogged.png

I'm using this api call to get the data.
https://api.fitbit.com/1/user/-/foods/log/date/<date>.json

 

I get all of the food items, but not all of the nutritionalValues in the JSON.  There's Calories, Fat, Fiber, Carbs, Sodium & Protein for the Chicken Burrito, but not for the other two.  Why?  Should I use a different api call?  Is it just not available?  Is there a bug?

Best Answer
0 Votes
22 REPLIES 22

Hi @RichUchytil 

 

Can you provide the JSON response for the food log that shows you're not getting the nutritional information?   I cannot reproduce this problem.

 

Thanks!

Gordon

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

Also, would please provide instructions on how you entered the food items?   

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

The JSON is below (I had to remove the dates from logDate as the web page was saying that's not permitted).  You can see nutritional information for Mixed Nuts and Chicken Burrito, but not for Cheerios, Pepsi, Zero Sugar and Salt & Pepper Potato Chips.  Yet when I look on the Fitbit website I see nutritional information for all of these.  Here is the api call we are making to generate the file.

https://api.fitbit.com/1/user/-/foods/log/date

 

I entered the food items by going to the Fitbit website and manually adding food with the Food Log.

 

 

 

{
  "foods": [
    {
      "isFavorite": false,
      "logDate": "",
      "logId": 31154620876,
      "loggedFood": {
        "accessLevel": "PUBLIC",
        "amount": 1,
        "brand": "General Mills",
        "calories": 100,
        "foodId": 14731799,
        "locale": "en_US",
        "mealTypeId": 1,
        "name": "Cheerios",
        "unit": {
          "id": 91,
          "name": "cup",
          "plural": "cups"
        },
        "units": [
          91,
          256,
          279,
          226,
          180,
          147,
          389
        ]
      }
    },
    {
      "isFavorite": false,
      "logDate": "",
      "logId": 31154660278,
      "loggedFood": {
        "accessLevel": "PUBLIC",
        "amount": 2,
        "brand": "",
        "calories": 360,
        "foodId": 81528,
        "locale": "en_US",
        "mealTypeId": 2,
        "name": "Mixed Nuts",
        "unit": {
          "id": 304,
          "name": "serving",
          "plural": "servings"
        },
        "units": [
          304,
          91,
          256,
          279,
          226,
          180,
          147,
          389
        ]
      },
      "nutritionalValues": {
        "calories": 360,
        "carbs": 12.19,
        "fat": 31.96,
        "fiber": 3.44,
        "protein": 11.61,
        "sodium": 199.68
      }
    },
    {
      "isFavorite": false,
      "logDate": "",
      "logId": 31151559759,
      "loggedFood": {
        "accessLevel": "PUBLIC",
        "amount": 1,
        "brand": "",
        "calories": 506,
        "foodId": 82969,
        "locale": "en_US",
        "mealTypeId": 3,
        "name": "Chicken Burrito",
        "unit": {
          "id": 40,
          "name": "burrito",
          "plural": "burritos"
        },
        "units": [
          40,
          304,
          226,
          180,
          147,
          389
        ]
      },
      "nutritionalValues": {
        "calories": 506,
        "carbs": 56.33,
        "fat": 21.33,
        "fiber": 3.67,
        "protein": 23,
        "sodium": 1527
      }
    },
    {
      "isFavorite": false,
      "logDate": "",
      "logId": 31159546483,
      "loggedFood": {
        "accessLevel": "PUBLIC",
        "amount": 1,
        "brand": "Pepsi",
        "calories": 0,
        "foodId": 769300664,
        "locale": "en_US",
        "mealTypeId": 3,
        "name": "Pepsi, Zero Sugar",
        "unit": {
          "id": 43,
          "name": "can",
          "plural": "cans"
        },
        "units": [
          43
        ]
      }
    },
    {
      "isFavorite": false,
      "logDate": "",
      "logId": 31166817241,
      "loggedFood": {
        "accessLevel": "PUBLIC",
        "amount": 28,
        "brand": "Kettle Brand",
        "calories": 144,
        "foodId": 692142502,
        "locale": "en_US",
        "mealTypeId": 3,
        "name": "Salt & Pepper Potato Chips",
        "unit": {
          "id": 147,
          "name": "gram",
          "plural": "grams"
        },
        "units": [
          60,
          226,
          180,
          147,
          389
        ]
      }
    }
  ],
  "summary": {
    "calories": 1110,
    "carbs": 104.31,
    "fat": 64.63,
    "fiber": 11.55,
    "protein": 39.76,
    "sodium": 2107.71,
    "water": 473.17599487304688
  }
}

 

 

 

 

Best Answer
0 Votes

Hi @RichUchytil 

 

I haven't been able to determine any differences in logging foods that would prevent the nutritional information from being returned.   I don't have this problem.

 

1. I search for the food, in this case Pepsi Zero sugar, and I select the first one in the list.

Screenshot 2023-03-22 at 9.23.08 AM.png

2. Here you can see I have added it to my lunch.

 

Screenshot 2023-03-22 at 9.24.06 AM.png

 

3. When I query the endpoint Get Food Log by Date, https://api.fitbit.com/1/user/-/foods/log/date/2023-03-22.json, I get this response.   You'll see the foodId is the same as yours' and I get the nutritional information returned.

 

Screenshot 2023-03-22 at 9.27.42 AM.png

 

Are there any differences between the way I add the food to my food log vs what you are doing?  If you don't see any differences, what tool are you using to query your food logs?   Have you tried the Fitbit Web API Explorer to see if you get the same response?

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

We are getting the data through a C# program, but I've also used Postman to make the same call and I get the same data.  Can you try something for me?  Add a second item for Lunch and see if you get the nutritional information for that item?  I just added a second item to my Breakfast (Toast) and Morning Snack (String Cheese).  Making the call through Postman, I now get nutritional information for String Cheese, Mixed Nuts, and Chicken Burrito.  Nothing for Toast.  I thought maybe it was only sending the information for the first item, but I get it for both Morning Snack items.

FoodLogged.png

 

Oh that's interesting.  I tried the Firbit Web API Explorer and that gives me nutritional information for everything.  What's the difference?  Why is it getting everything and we're not?  I created a Fitbit App, entered my Client ID & Client Secret on this page: OAuth 2.0 Tutorial (fitbit.com), and got the bearer token that I used with Postman.  I think I'm doing it correctly.

 

One thing I just tried and it worked.  In Postman, I replace the bearer token with the one from Swagger.  Since that worked, I'm guessing maybe there's something wrong with my App setup?

 

 

Best Answer
0 Votes

That is interesting.    I tried a different tool and I think I reproduced the problem.   Let me play around with it later today and get back to you.   My initial gut feeling is the tools are having a problem interpreting the JSON response.

 

 

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

Whew!  Nice to hear you can duplicate the problem.  Thanks much!  🙂 

Best Answer
0 Votes

Hi!  Just checking to see if you've been able to make any progress on this.  Thanks!  🙂 

Best Answer
0 Votes

Hi @RichUchytil 

 

I've been testing this problem with various tools (e.g. Fitbit Web API Explore (based on Swagger), Java program, Postman, curl, and VS Code Rest Client extension).   I'm seeing when curl is used, the nutritional values for all foods is returned.  When not using curl, the nutritional values for certain foods is not being returned.   My gut is telling me it is related to having a food item in the food log that has zero calories.   Why?   Not sure yet.   Since curl, or curl based tools, returned the data, I don't have 100% certainty whose problem this is.

 

I'm still investigating...

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

Hi @GordonFitbit 

 

Thanks much for the info.  That is curious.  I wonder if zero calories is seen as null or empty which is causing the entire dataset to be null/empty, so there is no data to return?

 

Much appreciate your help with this!

Best Answer
0 Votes

Hi @GordonFitbit 

 

Do you have any update on this?  Thanks!

Best Answer
0 Votes

Hi @GordonFitbit 

 

Just checking to see if you have an update on this.  We've got a process on hold waiting for a resolution to this.  Thanks!

Best Answer
0 Votes

Hi @RichUchytil 

 

My apologies for the delay.  I don't have an answer for you right now.   Is there a way your application can call the endpoint through a direct cUrl command?   That's the only workaround I have for retrieving the data.   I'm not sure what language you're writing your application, but here is an example of how to do it in Java, https://www.baeldung.com/java-curl.

 

Gordon

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

We've written it in C#.  I'll ask if we can user curl.  When you mentioned it was working with curl before we decided to wait until this way was fixed, but it sounds like it's not going to be done anytime soon.  If you ever do get an answer could you post it here?  Thanks very much for all your help!  🙂 

Best Answer
0 Votes

I thought I saw a C# example.   Let me see if I can find it again.   

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

Check out these examples.   I hope they are still relevant

 

https://www.delftstack.com/howto/csharp/csharp-curl/

https://social.msdn.microsoft.com/forums/en-US/562c9f44-4909-4993-807c-9aa1b3bab9c9/curl-call-with-c...

 

Gordon

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

Great!  Thanks much!

Best Answer
0 Votes

@GordonFitbit The business users aren't in any hurry to get this information, so I've been told not to use curl and wait for Fitbit to come up with a solution with the api.  It's nice to know we have another option, but looks like we'll just wait to see if you/Fitbit can figure this out.  Let me know if you come up with anything, and I'll probably ping you once a month to see how it's going.  Good luck and thanks again very much for all your help!  🙂

Best Answer
0 Votes

@GordonFitbit Hi!  It's been a few months so I thought I'd check and see if any progress has been made on this issue?  Hope you're having a great summer! Thanks!

Best Answer
0 Votes