USDA / USDA-APIs

Do you have feedback, ideas, or questions for USDA APIs? Use this repository's Issue Tracker to join the discussion.
www.usda.gov/developer
107 stars 16 forks source link

Regarding Search ingredient by nutrients #97

Open manijcgvak opened 4 years ago

manijcgvak commented 4 years ago

In old API

http://api.nal.usda.gov/ndb/nutrients?offset=0&max=50&nutrients=208

{ "report": { "sr": "1", "groups": "All groups", "subset": "All foods", "end": 1, "start": 0, "total": 7524, "foods": [ { "ndbno": "09427", "name": "Abiyuch, raw", "weight": 114, "measure": "0.5 cup", "nutrients": [ { "nutrient_id": "208", "nutrient": "Energy", "unit": "kcal", "value": "79", "gm": 69 } ] } ] } }

what is the alternative API to search ingredient based on nutrients?

And one more need, In case if the nutrient number is wrong in old API we get as

{ "errors": { "error": [ { "status": 400, "parameter": "nutrients", "message": "Invalid nutrient values. Please insure all nutrient parameters are valid nutrient numbers" } ] } }

But now we get the ingredients based on fdcId in Food Details endpoint, Is it possible to filter based on the nutrient in search end point and what is the alternative solution to get the ingredient only if the specified nutrient is available as used in the old API?

hphungnal commented 4 years ago

@manijcgvak There is not a way to directly filter/search based on nutrients in the FDC API. You can request only specific nutrients when getting food details from the "food" (https://fdc.nal.usda.gov/api-spec/fdc_api.html#/FDC/getFood) or "foods" (https://fdc.nal.usda.gov/api-spec/fdc_api.html#/FDC/getFoods) endpoint. The workaround I would suggest is to use the "list" endpoint to get foods and then use the "foods" endpoint to filter for the nutrients you want. We will discuss with FDC program about possibly adding a nutrient search.

manijcgvak commented 3 years ago

Is there any possibility for search by nutrient?