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

Create Food Log Delay

Hi,


When I want to create a food log via API for a given day, the food log is created in Fitbit, but after a few hours, I want to ask if this is expected? And what is the exact time I need to wait until the food log is created in Fitbit?

 

On API documentation, this part is not specified: 
https://dev.fitbit.com/build/reference/web-api/nutrition/create-food-log/

Best Answer
0 Votes
6 REPLIES 6

Any idea?

Best Answer
0 Votes

Hi @gentritabazi01 

 

I tested the endpoint based on the example in the documentation and I do not exhibit a delay.   Would you please provide the complete endpoint including the parameters that you're executing?

 

Gordon

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

Hi @GordonFitbit ,

 

I'm seeing the same behaviour when I log food via its foodName, e.g.

 

 

curl --request POST \ --url 'https://api.fitbit.com/1/user/-/foods/log.json?foodName=Lunch&date=2022-06-01&mealTypeId=2&calories=350&brandName=Cantine%20At%20Work&amount=1.00&unitId=304' \ --header 'Authorization: Bearer ...'

 

 

I get HTTP201 Created and a logId in the response body (logId changes for every request) so the request has been successful. However, most of the time (>90%) there is a delay until the food shows up, e.g. via

 

 

curl --request GET \ --url https://api.fitbit.com/1/user/-/foods/log/date/today.json \ --header 'Authorization: Bearer ...'

 

 

As I'm writing this, the delay is already 15 min. I have never observed the delay for POST ../foods/log.json calls where a foodId is given.

Matter of fact, logging via foodId does not only still work reliably, it also appears to be a trigger to process all the previous pending foodName-based logs. As soon as I log food via foodId, the delayed foodName-logs show up and get returned by GET /foods/log/date/today.json

 

 

curl --request POST \ --url 'https://api.fitbit.com/1/user/-/foods/log.json?foodId=537211326&date=today&mealTypeId=5&unitId=147&amount=100.00' \ --header 'Authorization: Bearer ...'

 

 

Some pointers to help you debug:

 

  • I have been using the API extensively for 4-5 years now and have never observed this behaviour until maybe 6-8 weeks ago, April should be around the time where the regression was introduced
  • Logging via foodName occasionally still works. I have a nightly (CET timezone) cron job that uses logging via foodName to carry over potential excess calories to the next day. That appears to still work reliably and I haven't observed it failing yet, however this might also be due to the delay between the job run and me checking in the morning

I'd appreciate you looking into this at it makes several workflows much more cumbersome for me

 

Regards

Markus

Best Answer
0 Votes

Hi @markusz 

 

Thank you for providing the additional information.   I'll will investigate further.

 

Gordon

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

Hi @gentritabazi01 and @markusz 

 

I'm having trouble reproducing this problem.   I have some questions for you that might help in my investigation.

 

1. Does the delay happen when the custom food is the first entry for a given date?

2. Does the delay happen when the custom food is entered after other food items are entered on the specified date?

3. Is the same custom food being entered multiple times on the same date?

4. Does the delay occur when entering a new custom food or an existing custom food?

5. How often does the delay occur (i.e. every new custom food entered)?   

 

Thanks!

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

Hi Gordon,

 

thanks for getting back to me. Can you confirm, that when you say custom food, you refer to food added to the food log via the foodName parameter, as described here: https://dev.fitbit.com/build/reference/web-api/nutrition/create-food-log/

 

An example command where I see the delay is this one from my initial post:

 

 

 

 

curl --request POST \ --url 'https://api.fitbit.com/1/user/-/foods/log.json?foodName=Lunch&date=2022-06-01&mealTypeId=2&calories=350&brandName=Cantine%20At%20Work&amount=1.00&unitId=304' \ --header 'Authorization: Bearer ...'

 

 

 

 

Regarding your question:

 

1. I'm not sure. What I observe is that the nightly cron job that carries over excess calories to the next day via the above API call always results in this delta showing up the next day.  I'll have to change my scripts to check whether this happens because the first call always succeeds or because the delay between the API call and me checking is large enough

2. Yes

3. I'd say it's not the same food, primarily for the reason that there is no foodId (neither custom nor general) that I provide in the API call when creating the log. I always log via the above API call where I get back a logId, but even then in almost every case calories and/or foodName is different from the previous call.

4. I believe you refer to custom food as described in this doc: https://dev.fitbit.com/build/reference/web-api/nutrition/create-food/. If so, that is not part of my workflow, I exclusively use the one I linked in the beginning

5. It's hard to tell exactly, but it's certainly not for every call. I just tried it 10 times - the first time the log succeeded, the other 9 didn't. Only after I then logged a food via foodId, all the 9 pending logs via foodName showed up as well

 

 

Thanks

Best Answer