Food Analysis

This resource provides a way to analyze Foods, Food Results, and external foods for nutritional content.

Note: The Nutrients in the response can vary by API key.

Resource URI

/analysis

Resource Parameters

Requests to this resource require a message body containing an object with the following fields:

NameTypeDescription
items array of Food Item The items to analyze

Food Item Properties

A Food Item is an object with the following fields:

NameTypeDescription
id string The unique identifier of the food
quantity number The quantity of the food
unit string The unique identifier of the food's unit

External Food Properties

To include external foods (ones not in the ESHA database), you may also include:

NameTypeDescription
nutrient_data array of Nutrient Data Point The nutrient values of the food to be included in the analysis
description string The description of the external food

When sending external foods, it is crucial to set the request Content-Type header to:

application/vnd.com.esha.data.Foods+json

Resource Properties

This resource is represented as an object with the following fields:

NameTypeDescription
items array of Analyzed Food The items analyzed
results array of Nutrient Data Point The results of the analysis

Analyzed Food Properties

An Analyzed Food is an object with the following fields:

NameTypeDescription
id string The unique identifier of the food
description string A human-readable description of the food
quantity number The quantity of the food
unit string The unique identifier of the food's unit
modified string The date (in ISO 8601 format) that the food was last updated
discontinued boolean If true the food has been discontinued

Nutrient Data Point Properties

A Nutrient Data Point is an object with the following fields:

NameTypeDescription
nutrient string The unique identifier of the Nutrient
value number The analyzed value

Supported Operations

Analyze Foods (HTTP POST)

HTTP POST accepts a JSON document containing the foods to be analyzed and returns a JSON document containing the results.

Example Request

POST /analysis?apikey=d9eea4cc28c342a2a7fc49d307860c03
Accept: application/json
Content-Type: application/vnd.com.esha.data.Foods+json

{
  "items": [
    {
      "id": "urn:uuid:17dbb668-f3f4-4822-8566-f46496887edc",
      "quantity": 0.5,
      "unit": "urn:uuid:dfad1d25-17ff-4201-bba0-0711e8b88c65"
    },
    {
      "id": "external_food1",
      "quantity": 1,
      "unit": "urn:uuid:85562e85-ba37-4e4a-8400-da43170204a7",
      "nutrient_data": [
        { 
          "nutrient": "urn:uuid:a4d01e46-5df2-4cb3-ad2c-6b438e79e5b9",
          "value": 137
        }
      ]
    } 
  ]
}

Example Response

HTTP/1.1 200 OK
Content-Type: application/json

{
  "items": [
    {
      "id": "urn:uuid:17dbb668-f3f4-4822-8566-f46496887edc",
      "description": "Broccoli, fresh",
      "quantity": 0.5,
      "unit": "urn:uuid:dfad1d25-17ff-4201-bba0-0711e8b88c65",
      "modified": "2011-10-04"
    },
    {
       "id": "external_food1",
       "modified": "2016-06-10",
       "quantity": 1,
       "unit": "urn:uuid:85562e85-ba37-4e4a-8400-da43170204a7"
    }
  ],
  "results: [
    {
      "nutrient": "urn:uuid:a4d01e46-5df2-4cb3-ad2c-6b438e79e5b9",
      "value": 152.47
    },
    ...
  ]
}