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

Inconsistent empty search result on the Search Food endpoint

Hello,

 

I have a problem with the search food endpoint. (https://dev.fitbit.com/docs/food-logging/#search-foods)

Randomly, I am receiving empty results for queries that I know have results. 

For example with query=Apple, I can receive foods=[ ]. My workaround is to repeat the request and in 2 -5 repeated requests, I eventually receive a valid response (foods = [ {food1}, {food2}, ...]).

 

All the requests are resolving with a 200 and the one with empty responses are not different to the successful ones in other ways that the foods is empty or not.

 

Thanks for the help,

Best Answer
7 REPLIES 7

Hi @agarant,

 

I'm having this issue too. Out of 10 search requests, about 3 requests of random order return empty. 

All requests are identical, though.

 

Were you able to find a workaround?

 

Thanks,

cadenza_97

Best Answer
0 Votes

Hi @GordonFitbit,

 

I ran into the same problem as described in this post: https://community.fitbit.com/t5/Web-API-Development/Inconsistent-empty-search-result-on-the-Search-F...

 

But, I noticed that this is true only when I'm looking for PRIVATE food. 

I.e., if I try searching for a string from the name of a PRIVATE food item 10 times in a row, about 3 of those times, I get an empty array. For the same request each of those 10 times.

 

While I could not find any documentation, I wanted to know - is there was any way to search only PRIVATE food by passing another parameter, like "accessLevel"?

 

Also, if possible, could you please list what attributes the querystring is searched on? For eg, can I use the optional description parameter from the Create Food API to boost my PRIVATE food in any way?

 

Thanks,

S

Best Answer
0 Votes

Hi @agarant @cadenza_97,

 

I'm sorry to hear that you are coming across empty results when using the Search Foods endpoint. I attempted query the endpoint now and was able to receive a response for "apple" without fail.

 

So that I can get a better understanding of what is occurring, can you provide me with timestamps of when you executed these API calls? It is possible that it may have lined up with some of our maintenance times. If you don't have this information, please keep times stamps of your next failed attempts and provide that information to me.

 

I look forward to hearing from you. Let me know if you have any additional questions in the meantime.

Best Answer
0 Votes

Hi @JohnFitbit,

 

The search appears to return an empty value only in a certain edge cases. But it is definitely inconsistent for private food search.

 

I created a private food with the name: 

fav food abcde

 

I then searched for this food using the string "abcde" with the Food Search Web API. 

 

This search returns the expected result about 70% of the time.

 

Here's a result where everything looks okay:

[
    {
        "accessLevel": "PRIVATE",
        "brand": "",
        "calories": 0,
        "creatorEncodedId": "7DHMM3",
        "defaultServingSize": 1,
        "defaultUnit": {
            "id": 1,
            "name": "almond",
            "plural": "almonds"
        },
        "foodId": 759403046,
        "isGeneric": false,
        "name": "fav food abcde",
        "units": [
            1
        ]
    },
    {
        "accessLevel": "PUBLIC",
        "brand": "Polaner",
        "calories": 50,
        "creatorEncodedId": "228TQ7",
        "defaultServingSize": 1,
        "defaultUnit": {
            "id": 349,
            "name": "tbsp",
            "plural": "tbsp"
        },
        "foodId": 37870,
        "isGeneric": false,
        "locale": "en_US",
        "name": "Fancy Fruit, Apicot Spread",
        "units": [
            349,
            147
        ]
    }
]

 

Here's another, for the exact same request, that is not:

[
    {
        "accessLevel": "PUBLIC",
        "brand": "Polaner",
        "calories": 50,
        "creatorEncodedId": "228TQ7",
        "defaultServingSize": 1,
        "defaultUnit": {
            "id": 349,
            "name": "tbsp",
            "plural": "tbsp"
        },
        "foodId": 37870,
        "isGeneric": false,
        "locale": "en_US",
        "name": "Fancy Fruit, Apicot Spread",
        "units": [
            349,
            147
        ]
    }
]

 

The problem is that search results are not predictable. If I use numbers, like "12345", the search is occasionally empty. It will be useful for my use-case to understand whether the foodDescription field from the Create Food API is searched with a boost value so that I can move "abcde" to the description.

 

I guess my end goal is to be able to tag privately created food with different values, or to refine my search to just private food.

 

Appreciate your help.

 

Thanks,

S

 

 

Best Answer
0 Votes

@agarant @cadenza_97 Thanks for reporting this issue and I was able to reproduce it.

 

I created TestFood1, TestFood2, and TestFood3 and queried "TestFood1" to see if it would show up in the Search Foods endpoint:

 

https://api.fitbit.com/1/foods/search.json?query=TestFood1

 

 

{
  "foods": [
    {
      "accessLevel": "PRIVATE",
      "brand": "",
      "calories": 100,
      "creatorEncodedId": "<user_id>",
      "defaultServingSize": 1,
      "defaultUnit": {
        "id": 253,
        "name": "piece (small)",
        "plural": "piece (small)s"
      },
      "foodId": 759623399,
      "isGeneric": false,
      "name": "TestFood1",
      "units": [
        253
      ]
    },
    {
      "accessLevel": "PRIVATE",
      "brand": "",
      "calories": 100,
      "creatorEncodedId": "<user_id>",
      "defaultServingSize": 1,
      "defaultUnit": {
        "id": 256,
        "name": "pint",
        "plural": "pints"
      },
      "foodId": 759738205,
      "isGeneric": false,
      "name": "TestFood2",
      "units": [
        256
      ]
    },
    {
      "accessLevel": "PRIVATE",
      "brand": "",
      "calories": 100,
      "creatorEncodedId": "<user_id>",
      "defaultServingSize": 1,
      "defaultUnit": {
        "id": 260,
        "name": "plank",
        "plural": "planks"
      },
      "foodId": 759738247,
      "isGeneric": false,
      "name": "TestFood3",
      "units": [
        260
      ]
    },
    {
      "accessLevel": "PUBLIC",
      "brand": "",
      "calories": 100,
      "creatorEncodedId": "<user_id>",
      "defaultServingSize": 1,
      "defaultUnit": {
        "id": 304,
        "name": "serving",
        "plural": "servings"
      },
      "foodId": 79329,
      "isGeneric": false,
      "locale": "en_US",
      "name": "Test Food 11-28 Chrome",
      "units": [
        304,
        349
      ]
    },
    {
      "accessLevel": "PUBLIC",
      "brand": "",
      "calories": 10,
      "creatorEncodedId": "<user_id>",
      "defaultServingSize": 1,
      "defaultUnit": {
        "id": 304,
        "name": "serving",
        "plural": "servings"
      },
      "foodId": 79328,
      "isGeneric": false,
      "locale": "en_US",
      "name": "Test Food 11-28 IE",
      "units": [
        304,
        349
      ]
    },
    {
      "accessLevel": "PUBLIC",
      "brand": "",
      "calories": 100,
      "creatorEncodedId": "<user_id>",
      "defaultServingSize": 1,
      "defaultUnit": {
        "id": 304,
        "name": "serving",
        "plural": "servings"
      },
      "foodId": 79330,
      "isGeneric": false,
      "locale": "en_US",
      "name": "Test Food 11-28 FF",
      "units": [
        304,
        349
      ]
    },
    {
      "accessLevel": "PUBLIC",
      "brand": "Care",
      "calories": 80,
      "defaultServingSize": 0.25,
      "defaultUnit": {
        "id": 91,
        "name": "cup",
        "plural": "cups"
      },
      "foodId": 747239791,
      "isGeneric": false,
      "locale": "en_US",
      "name": "Tastifit Coconut Cream Alternative",
      "units": [
        91
      ]
    },
    {
      "accessLevel": "PUBLIC",
      "brand": "GU",
      "calories": 100,
      "defaultServingSize": 1,
      "defaultUnit": {
        "id": 229,
        "name": "packet",
        "plural": "packets"
      },
      "foodId": 749512424,
      "isGeneric": false,
      "locale": "en_US",
      "name": "Energy Gel, Tastefully Nude",
      "units": [
        229,
        147
      ]
    }
  ]
}

 

 

I executed this call twice and received the above response twice. However, the entries did not appear on the 3rd attempt, see below:

 

 

{
  "foods": [
    {
      "accessLevel": "PUBLIC",
      "brand": "",
      "calories": 100,
      "creatorEncodedId": "<user_id>",
      "defaultServingSize": 1,
      "defaultUnit": {
        "id": 304,
        "name": "serving",
        "plural": "servings"
      },
      "foodId": 79329,
      "isGeneric": false,
      "locale": "en_US",
      "name": "Test Food 11-28 Chrome",
      "units": [
        304,
        349
      ]
    },
    {
      "accessLevel": "PUBLIC",
      "brand": "",
      "calories": 10,
      "creatorEncodedId": "<user_id>",
      "defaultServingSize": 1,
      "defaultUnit": {
        "id": 304,
        "name": "serving",
        "plural": "servings"
      },
      "foodId": 79328,
      "isGeneric": false,
      "locale": "en_US",
      "name": "Test Food 11-28 IE",
      "units": [
        304,
        349
      ]
    },
    {
      "accessLevel": "PUBLIC",
      "brand": "",
      "calories": 100,
      "creatorEncodedId": "<user_id>",
      "defaultServingSize": 1,
      "defaultUnit": {
        "id": 304,
        "name": "serving",
        "plural": "servings"
      },
      "foodId": 79330,
      "isGeneric": false,
      "locale": "en_US",
      "name": "Test Food 11-28 FF",
      "units": [
        304,
        349
      ]
    },
    {
      "accessLevel": "PUBLIC",
      "brand": "Care",
      "calories": 80,
      "defaultServingSize": 0.25,
      "defaultUnit": {
        "id": 91,
        "name": "cup",
        "plural": "cups"
      },
      "foodId": 747239791,
      "isGeneric": false,
      "locale": "en_US",
      "name": "Tastifit Coconut Cream Alternative",
      "units": [
        91
      ]
    },
    {
      "accessLevel": "PUBLIC",
      "brand": "GU",
      "calories": 100,
      "defaultServingSize": 1,
      "defaultUnit": {
        "id": 229,
        "name": "packet",
        "plural": "packets"
      },
      "foodId": 749512424,
      "isGeneric": false,
      "locale": "en_US",
      "name": "Energy Gel, Tastefully Nude",
      "units": [
        229,
        147
      ]
    }
  ]
}

 

 

I will be following up with the team to investigate this further and I will post updates once I receive them.

 

Thanks for your patience thus far, and let me know if you have any additional questions in the meantime.

Best Answer

Hi

 

Nothing since 2019 about this ? I experience the same thing and it's very annoying...

 

Thanks.

Best Answer

Hi @spoulin23,

 

Sorry for any inconvenience this has caused. I've reached out to engineering for an update as well and I'll follow up if I hear of any progress on this.

Best Answer
0 Votes