jalpnik
jalpnik

Reputation: 23

How can I call multiple nutrient information from ESHA Research API? (apid.esha.com)

I want to call ESHA Research nutrient REST API. I cannot seem to figure out how to call multiple nutrients using ESHA REST API. So far I am calling the following and only able to retrieve the calories, or protein, or another type of nutrient information. So I was hoping someone had experience in retrieving all the nutrient information with one call. Is this possible?

This is how I call to retrieve the TWIX nutrient

http://api.esha.com/analysis?apikey=xxxx&fo=urn:uuid:81d268ac-f1dc-4991-98c1-1b4d3a5006da (returns calories, please note the api key is not xxxx but instead a key generated from Esha once you sign up as developer) The return is JSON format.

If I want to call fat it would be the following http://api.esha.com/analysis?apikey=xxxx&fo=urn:uuid:81d268ac-f1dc-4991-98c1-1b4d3a5006da&n=urn:uuid:589294dc-3dcc-4b64-be06-c07e7f65c4bd

How can I make a call once and get a return of all the nutrients (so Fat, Calories, Carbs, Vitamins, etc..) for a particular food ID? I have researched and looked at this for a while and cannot seem to find the answer.

Thanks in advance for your help.

Upvotes: 2

Views: 277

Answers (2)

twaddington
twaddington

Reputation: 11645

From briefly looking at their documentation this looks to be a very poorly designed API. That being said, it looks like you might be able to achieve this by calling the Analyze Foods (HTTP POST) endpoint. Their documentation makes it look like the response will include a list of all the analyzed nutrients.

Edit: I played around with their API and couldn't get it to return a response with multiple nutrients. It's possible that the items I requested didn't have multiple results. Although, it's equally possible the API is simply broken and returning bad data. You might want to contact them to confirm.

Here's an example request using curl:

curl -v "http://api.esha.com/analysis?apikey=XXXX" -H "Content-Type: application/json" -X POST -d '{ "items": [ { "id": "urn:uuid:eaa21583-13cc-4cd6-b8e1-8a2901cdcdff", "quantity": 0.75, "unit": "urn:uuid:dfad1d25-17ff-4201-bba0-0711e8b88c65" } ] }' | jsonpp

Upvotes: 0

Dudboi
Dudboi

Reputation: 26

This probably doesn't help very much, but you could pass in multiple foods using f0, f1 etc. This gets you a combined nutrient list (a sum of that nutrient for all foods) as opposed to multiple lists of nutrients. I haven't figured it out either, and currently work around it by making individual calls for each food

Upvotes: 1

Related Questions