Sign in | Sign up

Nutritionix.com Demo

Tagged:

Currently contains 5 posts

Avatar

April 11, 2013 16:57

Matt Silverman

You can test out the API by running a search on:
http://www.nutritionix.com/search?q=celery

OR
http://m.nutritionix.com

Avatar

June 10, 2013 23:28

zyphlar

Am I doing something wrong with the Ruby on Rails sample code? Celery returns one result, the sample code’s search, “tacos”, returns nothing… as does milk, banana, apples… Am I looking at the same API?

1.9.3-p385 :014 > agent = Nutritionix::API.new(“redacted_id”,“redacted_key”)

1.9.3-p385 :055 > agent.search(‘milk’)
=> “{\”total_hits\“:0,\”max_score\“:null,\”hits\“:[]}”
1.9.3-p385 :056 > agent.search(‘tacos’)
=> “{\”total_hits\“:0,\”max_score\“:null,\”hits\“:[]}”
1.9.3-p385 :057 > agent.search(‘banana’)
=> “{\”total_hits\“:0,\”max_score\“:null,\”hits\“:[]}”
1.9.3-p385 :058 > agent.search(‘apples’)
=> “{\”total_hits\“:0,\”max_score\“:null,\”hits\“:[]}”
1.9.3-p385 :059 > agent.search(‘taco’)
=> “{\”total_hits\“:9,\”max_score\“:2.9908752,\”hits\“:[{\”index\“:\”c3c99fgjes5keop0gzsc\“,\”type\“:\”item\“,\”id\“:\”513fc9ce673c4fbc2600724f\“,\”score\“:2.9908752,\”fields\“:{\”item_id\“:\”513fc9ce673c4fbc2600724f\“,\”item_name\“:\”Hard Taco Kids Hard Taco\“,\”brand_name\“:\”Mucho Burrito\“}},{\”index\“:\”c3c99fgjes5keop0gzsc\“,\”type\“:\”item\“,\”id\“:\”513fc994927da7040800207f\“,\”score\“:2.6694565,\”fields\“:{\”item_id\“:\”513fc994927da7040800207f\“,\”item_name\“:\”Taco Sauce\“,\”brand_name\“:\”Jack in the Box\“}},{\”index\“:\”c3c99fgjes5keop0gzsc\“,\”type\“:\”item\“,\”id\“:\”513fc997927da704080046b0\“,\”score\“:1.002525,\”fields\“:{\”item_id\“:\”513fc997927da704080046b0\“,\”item_name\“:\”Jalapeno peppers – 1 tablespoon\“,\”brand_name\“:\”Taco Del Mar\“}},{\”index\“:\”c3c99fgjes5keop0gzsc\“,\”type\“:\”item\“,\”id\“:\”513fc9cb673c4fbc26005207\“,\”score\“:0.8506707,\”fields\“:{\”item_id\“:\”513fc9cb673c4fbc26005207\“,\”item_name\“:\”Diet Pepsi 32 oz\“,\”brand_name\“:\”King Taco\“}},{\”index\“:\”c3c99fgjes5keop0gzsc\“,\”type\“:\”item\“,\”id\“:\”513fc9cb673c4fbc2600520f\“,\”score\“:0.8506707,\”fields\“:{\”item_id\“:\”513fc9cb673c4fbc2600520f\“,\”item_name\“:\”Diet Pepsi 21 oz\“,\”brand_name\“:\”King Taco\“}},{\”index\“:\”c3c99fgjes5keop0gzsc\“,\”type\“:\”item\“,\”id\“:\”513fc997927da704080046d0\“,\”score\“:0.80202,\”fields\“:{\”itemid\“:\”513fc997927da704080046d0\“,\”itemname\“:\”Diet Sodas Unsweetened Iced Tea 8 fl oz\“,\”brandname\“:\”Taco Del Mar\“}},{\”index\“:\”c3c99fgjes5keop0gzsc\“,\”type\“:\”item\“,\”id\“:\”513fc997927da704080046d6\“,\”score\“:0.80202,\”fields\“:{\”itemid\“:\”513fc997927da704080046d6\“,\”itemname\“:\”Diet Sodas Unsweetened Iced Tea 16 fl oz\“,\”brandname\“:\”Taco Del Mar\“}},{\”index\“:\”c3c99fgjes5keop0gzsc\“,\”type\“:\”item\“,\”id\“:\”513fc997927da704080046dc\“,\”score\“:0.80202,\”fields\“:{\”itemid\“:\”513fc997927da704080046dc\“,\”itemname\“:\”Diet Sodas Unsweetened Iced Tea 24 fl oz\“,\”brandname\“:\”Taco Del Mar\“}},{\”index\“:\”c3c99fgjes5keop0gzsc\“,\”type\“:\”item\“,\”id\“:\”513fc997927da704080046e2\“,\”score\“:0.80202,\”fields\“:{\”itemid\“:\”513fc997927da704080046e2\“,\”itemname\“:\”Diet Sodas Unsweetened Iced Tea 33 fl oz\“,\”brandname\“:\”Taco Del Mar\“}}]}”

I feel like I’m missing something major; it seems like an API issue moreso than a Ruby library issue. (https://github.com/mftaher/nutritionix-api-ruby-library)

Avatar

June 11, 2013 22:04

zyphlar

Ah, it appears that the API requires a nonzero cal_max, otherwise you’ll literally only get results with 0 calories (like diet beverages.) I would have expected a nil/zero parameter to mean “any” but I guess this makes some kind of sense too. I wonder what the maximum cal_max value is? Ten billion?

1.9.3-p385 :023 > agent.search(“milk”, 0, 10, 0, 0, nil, nil)
=> “{\”total_hits\“:0,\”max_score\“:null,\”hits\“:[]}”
1.9.3-p385 :024 > agent.search(“milk”, 0, 10, 0, 500000, nil, nil)
=> “{\”total_hits\“:11,\”max_score\“:10.037058,\”hits\“:[{\”index\“:\”c3c99fgjes5keop0gzsc\“,\”type\“:\”item\“,\”id\“:\”513fceb375b8dbbc210000e2\“,\”score\“:10.037058,\”fields\“:{\”item_id\“:\”513fceb375b8dbbc210000e2\“,\”item_name\“:\”Milk, whole, 3.25% milkfat, with added vitamin D – 1 quart\“,\”brand_name\“:\”USDA\“}},{\”index\“:\”c3c99fgjes5keop0gzsc\“,\”type\“:\”item\“,\”id\“:\”513fceb375b8dbbc210000e4\“,\”score\“:10.037058,\”fields\“:{\”item_id\“:\”513fceb375b8dbbc210000e4\“,\”item_name\“:\”Milk, whole, 3.25% milkfat, with added vitamin D – 1 tbsp\“,\”brand_name\“:\”USDA\“}},{\”index\“:\”c3c99fgjes5keop0gzsc\“,\”type\“:\”item\“,\”id\“:\”513fceb375b8dbbc210000e5\“,\”score\“:10.037058,\”fields\“:{\”item_id\“:\”513fceb375b8dbbc210000e5\“,\”item_name\“:\”Milk, whole, 3.25% milkfat, with added vitamin D – 1 cup\“,\”brand_name\“:\”USDA\“}},{\”index\“:\”c3c99fgjes5keop0gzsc\“,\”type\“:\”item\“,\”id\“:\”513fceb375b8dbbc210000f2\“,\”score\“:10.033088,\”fields\“:{\”item_id\“:\”513fceb375b8dbbc210000f2\“,\”item_name\“:\”Milk, lowfat, fluid, 1% milkfat, with added nonfat milk solids, vitamin A and vitamin D – 1 quart\“,\”brand_name\“:\”USDA\“}},{\”index\“:\”c3c99fgjes5keop0gzsc\“,\”type\“:\”item\“,\”id\“:\”513fceb375b8dbbc210000fa\“,\”score\“:10.033088,\”fields\“:{\”item_id\“:\”513fceb375b8dbbc210000fa\“,\”item_name\“:\”Milk, nonfat, fluid, with added nonfat milk solids, vitamin A and vitamin D (fat free or skim) – 1 fl oz\“,\”brand_name\“:\”USDA\“}},{\”index\“:\”c3c99fgjes5keop0gzsc\“,\”type\“:\”item\“,\”id\“:\”513fceb375b8dbbc2100017b\“,\”score\“:10.033088,\”fields\“:{\”item_id\“:\”513fceb375b8dbbc2100017b\“,\”item_name\“:\”Milk, reduced fat, fluid, 2% milkfat, with added nonfat milk solids, without added vitamin A – 1 cup\“,\”brand_name\“:\”USDA\“}},{\”index\“:\”c3c99fgjes5keop0gzsc\“,\”type\“:\”item\“,\”id\“:\”513fceb375b8dbbc210000f3\“,\”score\“:10.033087,\”fields\“:{\”itemid\“:\”513fceb375b8dbbc210000f3\“,\”itemname\“:\”Milk, lowfat, fluid, 1% milkfat, with added nonfat milk solids, vitamin A and vitamin D – 1 cup\“,\”brandname\“:\”USDA\“}},{\”index\“:\”c3c99fgjes5keop0gzsc\“,\”type\“:\”item\“,\”id\“:\”513fceb375b8dbbc210000f9\“,\”score\“:10.033087,\”fields\“:{\”itemid\“:\”513fceb375b8dbbc210000f9\“,\”itemname\“:\”Milk, nonfat, fluid, with added nonfat milk solids, vitamin A and vitamin D (fat free or skim) – 1 quart\“,\”brandname\“:\”USDA\“}},{\”index\“:\”c3c99fgjes5keop0gzsc\“,\”type\“:\”item\“,\”id\“:\”513fceb375b8dbbc210000fb\“,\”score\“:10.033087,\”fields\“:{\”itemid\“:\”513fceb375b8dbbc210000fb\“,\”itemname\“:\”Milk, nonfat, fluid, with added nonfat milk solids, vitamin A and vitamin D (fat free or skim) – 1 cup\“,\”brandname\“:\”USDA\“}},{\”index\“:\”c3c99fgjes5keop0gzsc\“,\”type\“:\”item\“,\”id\“:\”513fceb375b8dbbc2100017a\“,\”score\“:10.033087,\”fields\“:{\”itemid\“:\”513fceb375b8dbbc2100017a\“,\”itemname\“:\”Milk, reduced fat, fluid, 2% milkfat, with added nonfat milk solids, without added vitamin A – 1 quart\“,\”brandname\“:\”USDA\“}}]}”

June 11, 2013 22:16

Anonymous User

The max value is not set since it will only return results within the params you set. So if you state cal_min to 0 and max to 50000 it will return anything your looking for since we do not have anything over 5K I believe.

Avatar

January 20, 2015 05:07

menupages112

m I doing something wrong with the Ruby on Rails sample code? Celery returns one result, the sample code’s search, “tacos”, returns nothing… as does milk, banana, apples… Am I looking at the same API?

Reply to thread