fatsecret Platform API Documentation

Foods: Find Id For Barcode

OAuth 2.0 OAuth 1.0 Latest Premier Exclusive
Description

Returns detailed nutritional information for the specified food matching the barcode specified. Barcodes must be specified as GTIN-13 numbers - a 13-digit number filled in with zeros for the spaces to the left. UPC-A, EAN-13 and EAN-8 barcodes may be specified. UPC-E barcodes should be converted to their UPC-A equivalent (and then specified as GTIN-13 numbers).

An interactive demonstration of our Barcode API can be accessed here

Why are we introducing version 3?

New food classification levels, food form and nutrient content tags are now available and match the food.get.v6 response.

A food_classification property includes the hierarchy levels for this food in the classification property, and the food form in the food_form property. The hierarchy levels provide a three-level classification of the type of food being returned, and the food form indicates whether a food is a solid or a liquid, and for liquids whether it can be drunk and is therefore a beverage.

A nutrient_content_tags property includes a single reference_basis property that indicates the serving type used for tag calculation, and up to 9 nutrient entries under nutrients with applicable tags.

The food_classification property is enabled using the include_food_classification_data parameter, and the nutrient_content_tags property is enabled using the include_nutrient_content_tags parameter.

For more detailed information about these new data points see the Food Classification and Nutrient Content Tags documentation. The include_food_classification_data and include_nutrient_content_tags parameters are only available for Premier and Premier Free accounts, and can be enabled by getting in touch to enable Premier Exclusive features on your account.

Parameters
URL / Method
NAME TYPE REQUIRED DESCRIPTION
URL (new)
Method
N/A Required "https://platform.fatsecret.com/rest/food/barcode/find-by-id/v3"
HTTP "GET"
OR
method String Required "food.find_id_for_barcode.v3" (included with other parameters)
Additional Parameters
NAME TYPE REQUIRED DESCRIPTION
barcode String Required 13-digit GTIN-13 formatted sequence of digits representing the barcode to search against
include_food_classification_data Boolean Optional Either "true" or "false" - the response will include the food classification hierarchy and the food form (Solid, Liquid (non-beverage) or Beverage)
include_nutrient_content_tags Boolean Optional Either "true" or "false" - the response will include a nutrient content tag for each nutrient with a value
include_sub_categories Boolean Optional (Deprecated, use include_food_classification_data) Response will include the names of all sub categories associated with the food
include_food_attributes Boolean Optional Response will include food dietary preferences and allergens if available. (Requires separate premier offering, please contact us in order for this feature to be enabled for your account)
flag_default_serving Boolean Optional Either "true" or "false" - the response will flag one of the servings as the default serving (the suggested or most commonly chosen option)
region String Optional Results will be filtered by region. E.G.: "FR" returns results from France. If not specified this will default to "US" (United States). Click here for full documentation on localization.
language String Optional (Ignored unless region is also specified) Results will be in the specified language. E.G.: "fr" returns results in French
format String Optional The desired response format. Valid response formats are "xml" or "json" (default value is "xml").
Scopes for OAuth2 integration: premier, barcode
Response
The only storable values returned by this call are food_id and serving_id.

Each food element contains information as follows:

NAME TYPE DESCRIPTION
food_id Long Unique food identifier
food_name String Name of the food, not including the brand name. E.G.: "Instant Oatmeal"
brand_name String Brand name, only when food_type is "Brand". E.G.: "Quaker"
food_type String Takes the value "Brand" or "Generic". Indicates whether the food is a brand or generic item
food_url String URL of this food item on foods.fatsecret.com

Each allergen element contains information as follows:

NAME TYPE DESCRIPTION
id Long Unique allergen identifier
name String Allergen name (English only). Values include Egg, Fish, Gluten, Lactose, Milk, Nuts, Peanuts, Sesame, Shellfish, Soy
value Ternary Allergen value. Valid values are 1 (True), 0 (False) and -1 (Unknown). E.G.: Soy: 1 (Contains soy), 0 (Does not contain soy), -1 (Unknown)

Each preference element contains information as follows:

NAME TYPE DESCRIPTION
id Long Unique preference identifier
name String Preference name (English only). Values include Vegan, Vegetarian
value Ternary Preference value. Valid values are 1 (True), 0 (False) and -1 (Unknown). E.G.: Vegan: 1 (Is vegan), 0 (Is not vegan), -1 (Unknown)

Each level_1 element contains information as follows:

NAME TYPE DESCRIPTION
id Long Unique identifier for the broadest classification level
name String Name of the broadest classification level (English only). E.G.: Dairy Products and Eggs

Each level_2 element contains information as follows:

NAME TYPE DESCRIPTION
id Long Unique identifier for the second classification level
name String Name of the second classification level (English only). E.G.: Milk and Non-Dairy Milk

Each level_3 element contains information as follows:

NAME TYPE DESCRIPTION
id Long Unique identifier for the most specific classification level
name String Name of the most specific classification level (English only). E.G.: Milk

Each food_form element contains information as follows:

NAME TYPE DESCRIPTION
id Long How the food is measured and thresholded: 1 = Solid, 2 = Liquid (non-beverage), 3 = Beverage
name String Display name of the food form (English only). E.G.: Solid, Liquid (non-beverage), Beverage

Each nutrient_content_tags element contains information as follows:

NAME TYPE DESCRIPTION
reference_basis String The serving each nutrient content tag on this food was calculated against. E.G.: "100 g", "100 ml"

Each nutrient element contains information as follows:

NAME TYPE DESCRIPTION
id Long Unique nutrient identifier
identifier String Unique identifier label for the nutrient (English only). E.G.: fat, saturated_fat, sugar, sodium, protein, energy
name String Nutrient display name (English only). E.G.: Saturated Fat

Each tag element contains information as follows:

NAME TYPE DESCRIPTION
id Long Unique tag identifier used across one or more nutrients
name String Tag display name (English only). Can vary by nutrient for the same tag id. E.G.: Contains, Low, Fat Free. See the Nutrient Content Tags guide for more detail.

Each serving element contains information as follows:

NAME TYPE DESCRIPTION
serving_id Long Unique serving identifier
serving_description String Full description of the serving size. E.G.: "1 cup" or "100 g"
serving_url String URL of the serving size for this food item on foods.fatsecret.com
metric_serving_amount Decimal Metric quantity combined with metric_serving_unit to derive the total standardized quantity of the serving (where available)
metric_serving_unit String Metric unit of measure for the serving size – either "g" or "ml" or "oz" – combined with metric_serving_amount to derive the total standardized quantity of the serving (where available)
number_of_units Decimal Number of units in this standard serving size. For instance, if the serving description is "2 tablespoons" the number of units is "2", while if the serving size is "1 cup" the number of units is "1". For food_type "Brand" the number of units of the original serving is always "1", while any additional standardized servings use the metric amount (for example "100.0" for a 100 g serving).
measurement_description String A description of the unit of measure used in the serving description. For instance, if the description is "1/2 cup" the measurement description is "cup", while if the serving size is "100 g" the measurement description is "g". For food_type "Brand" the measurement description of the original serving is always "serving". Where that serving includes a serving amount, newer versions also return standardized servings (100 g, 100 ml, or 1 oz and 100 g) with a measurement description of "g", "ml" or "oz".
is_default Int (Premier Exclusive) Only included if it's the suggested or most commonly chosen option. If included equals 1
calories Decimal Energy content in kcal
carbohydrate Decimal Total carbohydrate content in grams
protein Decimal Protein content in grams
fat Decimal Total fat content in grams
saturated_fat Decimal Saturated fat content in grams (where available)
polyunsaturated_fat Decimal Polyunsaturated fat content in grams (where available)
monounsaturated_fat Decimal Monounsaturated fat content in grams (where available)
trans_fat Decimal Trans fat content in grams (where available)
cholesterol Decimal Cholesterol content in milligrams (where available)
sodium Decimal Sodium content in milligrams (where available)
potassium Decimal Potassium content in milligrams (where available)
fiber Decimal Fiber content in grams (where available)
sugar Decimal Sugar content in grams (where available)
added_sugars Decimal Added Sugars content in grams (where available)
vitamin_d Decimal Vitamin D content in micrograms (where available)
vitamin_a Decimal Vitamin A content in micrograms (where available)
vitamin_c Decimal Vitamin C content in milligrams (where available)
calcium Decimal Calcium content in milligrams (where available)
iron Decimal Iron content in milligrams (where available)

Example Response

Example 1:

<?xml version="1.0" encoding="utf-8"?>
<food xmlns="http://platform.fatsecret.com/api/1.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://platform.fatsecret.com/api/1.0/ http://platform.fatsecret.com/api/1.0/fatsecret.xsd">
  <food_id>50953</food_id>
  <food_name>Whole Grain Cheerios</food_name>
  <brand_name>General Mills</brand_name>
  <food_type>Brand</food_type>
  <food_url>https://foods.fatsecret.com/calories-nutrition/general-mills/whole-grain-cheerios</food_url>
  <food_attributes>
    <allergens>
      <allergen>
        <id>24904</id>
        <name>Fish</name>
        <value>-1</value>
      </allergen>
      <allergen>
        <id>24905</id>
        <name>Soy</name>
        <value>-1</value>
      </allergen>
      <allergen>
        <id>24906</id>
        <name>Nuts</name>
        <value>-1</value>
      </allergen>
      <allergen>
        <id>24907</id>
        <name>Lactose</name>
        <value>-1</value>
      </allergen>
      <allergen>
        <id>24908</id>
        <name>Shellfish</name>
        <value>-1</value>
      </allergen>
      <allergen>
        <id>24909</id>
        <name>Egg</name>
        <value>-1</value>
      </allergen>
      <allergen>
        <id>24910</id>
        <name>Sesame</name>
        <value>-1</value>
      </allergen>
      <allergen>
        <id>24911</id>
        <name>Peanuts</name>
        <value>-1</value>
      </allergen>
      <allergen>
        <id>24912</id>
        <name>Gluten</name>
        <value>-1</value>
      </allergen>
      <allergen>
        <id>24913</id>
        <name>Milk</name>
        <value>-1</value>
      </allergen>
    </allergens>
    <preferences>
      <preference>
        <id>24914</id>
        <name>Vegan</name>
        <value>-1</value>
      </preference>
      <preference>
        <id>24915</id>
        <name>Vegetarian</name>
        <value>-1</value>
      </preference>
    </preferences>
  </food_attributes>
  <food_classification>
    <classification>
      <level_1>
        <id>10004</id>
        <name>Grains, Pasta and Noodles</name>
      </level_1>
      <level_2>
        <id>20026</id>
        <name>Cereal Products</name>
      </level_2>
      <level_3>
        <id>30076</id>
        <name>Breakfast Cereals - Ready to consume</name>
      </level_3>
    </classification>
    <food_form>
      <id>1</id>
      <name>Solid</name>
    </food_form>
  </food_classification>
  <nutrient_content_tags>
    <reference_basis>100 g</reference_basis>
    <nutrients>
      <nutrient>
        <id>1</id>
        <identifier>energy</identifier>
        <name>Energy density</name>
        <tag>
          <id>104</id>
          <name>High</name>
        </tag>
      </nutrient>
      <nutrient>
        <id>2</id>
        <identifier>fat</identifier>
        <name>Fat</name>
        <tag>
          <id>105</id>
          <name>Contains</name>
        </tag>
      </nutrient>
      <nutrient>
        <id>3</id>
        <identifier>saturated_fat</identifier>
        <name>Saturated Fat</name>
        <tag>
          <id>100</id>
          <name>Free of</name>
        </tag>
      </nutrient>
      <nutrient>
        <id>4</id>
        <identifier>sugar</identifier>
        <name>Sugar</name>
        <tag>
          <id>102</id>
          <name>Low</name>
        </tag>
      </nutrient>
      <nutrient>
        <id>5</id>
        <identifier>sodium</identifier>
        <name>Sodium</name>
        <tag>
          <id>105</id>
          <name>Contains</name>
        </tag>
      </nutrient>
      <nutrient>
        <id>6</id>
        <identifier>cholesterol</identifier>
        <name>Cholesterol</name>
        <tag>
          <id>100</id>
          <name>Free</name>
        </tag>
      </nutrient>
      <nutrient>
        <id>7</id>
        <identifier>protein</identifier>
        <name>Protein</name>
        <tag>
          <id>106</id>
          <name>Reasonable</name>
        </tag>
      </nutrient>
      <nutrient>
        <id>8</id>
        <identifier>dietary_fiber</identifier>
        <name>Dietary Fiber</name>
        <tag>
          <id>104</id>
          <name>High</name>
        </tag>
      </nutrient>
      <nutrient>
        <id>9</id>
        <identifier>carbohydrate</identifier>
        <name>Carbohydrate</name>
        <tag>
          <id>104</id>
          <name>High</name>
        </tag>
      </nutrient>      
    </nutrients>
  </nutrient_content_tags>
  <servings>
    <serving>
      <serving_id>100675</serving_id>
      <serving_description>1 cup</serving_description>
      <serving_url>https://foods.fatsecret.com/calories-nutrition/general-mills/whole-grain-cheerios</serving_url>
      <metric_serving_amount>30.000</metric_serving_amount>
      <metric_serving_unit>g</metric_serving_unit>
      <number_of_units>1.000</number_of_units>
      <measurement_description>serving</measurement_description>
      <is_default>1</is_default>
      <calories>100</calories>
      <carbohydrate>20.00</carbohydrate>
      <protein>3.00</protein>
      <fat>2.00</fat>
      <saturated_fat>0</saturated_fat>
      <polyunsaturated_fat>0.500</polyunsaturated_fat>
      <monounsaturated_fat>0.500</monounsaturated_fat>
      <trans_fat>0</trans_fat>
      <cholesterol>0</cholesterol>
      <sodium>160</sodium>
      <potassium>170</potassium>
      <fiber>3.0</fiber>
      <sugar>1.00</sugar>
      <added_sugars>0</added_sugars>
      <vitamin_d>0</vitamin_d>
      <vitamin_a>0</vitamin_a>
      <vitamin_c>0</vitamin_c>
      <calcium>0</calcium>
      <iron>0</iron>
    </serving>
    <serving>
      <serving_id>0</serving_id>
      <serving_description>100 g</serving_description>
      <metric_serving_amount>100.0</metric_serving_amount>
      <metric_serving_unit>g</metric_serving_unit>
      <number_of_units>100.0</number_of_units>
      <measurement_description>g</measurement_description>
      <calories>333</calories>
      <carbohydrate>66.67</carbohydrate>
      <protein>10.00</protein>
      <fat>6.67</fat>
      <saturated_fat>0</saturated_fat>
      <polyunsaturated_fat>1.667</polyunsaturated_fat>
      <monounsaturated_fat>1.667</monounsaturated_fat>
      <trans_fat>0</trans_fat>
      <cholesterol>0</cholesterol>
      <sodium>533</sodium>
      <potassium>567</potassium>
      <fiber>10.0</fiber>
      <sugar>3.33</sugar>
      <added_sugars>0</added_sugars>
      <vitamin_d>0</vitamin_d>
      <vitamin_a>0</vitamin_a>
      <vitamin_c>0</vitamin_c>
      <calcium>0</calcium>
      <iron>0</iron>
    </serving>
  </servings>
</food>

Example 1:

{
  "food": {
    "food_id": "50953",
    "food_name": "Whole Grain Cheerios",
    "brand_name": "General Mills",
    "food_type": "Brand",
    "food_url": "https://foods.fatsecret.com/calories-nutrition/general-mills/whole-grain-cheerios",
    "food_attributes": {
      "allergens": {
        "allergen": [
          {
            "id": "24904",
            "name": "Fish",
            "value": "-1"
          },
          {
            "id": "24905",
            "name": "Soy",
            "value": "-1"
          },
          {
            "id": "24906",
            "name": "Nuts",
            "value": "-1"
          },
          {
            "id": "24907",
            "name": "Lactose",
            "value": "-1"
          },
          {
            "id": "24908",
            "name": "Shellfish",
            "value": "-1"
          },
          {
            "id": "24909",
            "name": "Egg",
            "value": "-1"
          },
          {
            "id": "24910",
            "name": "Sesame",
            "value": "-1"
          },
          {
            "id": "24911",
            "name": "Peanuts",
            "value": "-1"
          },
          {
            "id": "24912",
            "name": "Gluten",
            "value": "-1"
          },
          {
            "id": "24913",
            "name": "Milk",
            "value": "-1"
          }
        ]
      },
      "preferences": {
        "preference": [
          {
            "id": "24914",
            "name": "Vegan",
            "value": "-1"
          },
          {
            "id": "24915",
            "name": "Vegetarian",
            "value": "-1"
          }
        ]
      }
    },
    "food_classification": {
      "classification": {
        "level_1": {
          "id": "10004",
          "name": "Grains, Pasta and Noodles"
        },
        "level_2": {
          "id": "20026",
          "name": "Cereal Products"
        },
        "level_3": {
          "id": "30076",
          "name": "Breakfast Cereals - Ready to consume"
        }
      },
      "food_form": {
        "id": "1",
        "name": "Solid"
      }
    },
    "nutrient_content_tags": {
      "reference_basis": "100 g",
      "nutrients": {
        "nutrient": [
          {
            "id": "1",
            "identifier": "energy",
            "name": "Energy density",
            "tag": {
              "id": "104",
              "name": "High"
            }
          },
          {
            "id": "2",
            "identifier": "fat",
            "name": "Fat",
            "tag": {
              "id": "105",
              "name": "Contains"
            }
          },
          {
            "id": "3",
            "identifier": "saturated_fat",
            "name": "Saturated Fat",
            "tag": {
              "id": "100",
              "name": "Free of"
            }
          },
          {
            "id": "4",
            "identifier": "sugar",
            "name": "Sugar",
            "tag": {
              "id": "102",
              "name": "Low"
            }
          },
          {
            "id": "5",
            "identifier": "sodium",
            "name": "Sodium",
            "tag": {
              "id": "105",
              "name": "Contains"
            }
          },
          {
            "id": "6",
            "identifier": "cholesterol",
            "name": "Cholesterol",
            "tag": {
              "id": "100",
              "name": "Free"
            }
          },
          {
            "id": "7",
            "identifier": "protein",
            "name": "Protein",
            "tag": {
              "id": "106",
              "name": "Reasonable"
            }
          },
          {
            "id": "8",
            "identifier": "dietary_fiber",
            "name": "Dietary Fiber",
            "tag": {
              "id": "104",
              "name": "High"
            }
          },
          {
            "id": "9",
            "identifier": "carbohydrate",
            "name": "Carbohydrate",
            "tag": {
              "id": "104",
              "name": "High"
            }
          }
        ]
      }
    },
    "servings": {
      "serving": [
        {
          "serving_id": "100675",
          "serving_description": "1 cup",
          "serving_url": "https://foods.fatsecret.com/calories-nutrition/general-mills/whole-grain-cheerios",
          "metric_serving_amount": "30.000",
          "metric_serving_unit": "g",
          "number_of_units": "1.000",
          "measurement_description": "serving",
          "is_default": "1",
          "calories": "100",
          "carbohydrate": "20.00",
          "protein": "3.00",
          "fat": "2.00",
          "saturated_fat": "0",
          "polyunsaturated_fat": "0.500",
          "monounsaturated_fat": "0.500",
          "trans_fat": "0",
          "cholesterol": "0",
          "sodium": "160",
          "potassium": "170",
          "fiber": "3.0",
          "sugar": "1.00",
          "added_sugars": "0",
          "vitamin_d": "0",
          "vitamin_a": "0",
          "vitamin_c": "0",
          "calcium": "0",
          "iron": "0"
        },
        {
          "serving_id": "0",
          "serving_description": "100 g",
          "metric_serving_amount": "100.0",
          "metric_serving_unit": "g",
          "number_of_units": "100.0",
          "measurement_description": "g",
          "calories": "333",
          "carbohydrate": "66.67",
          "protein": "10.00",
          "fat": "6.67",
          "saturated_fat": "0",
          "polyunsaturated_fat": "1.667",
          "monounsaturated_fat": "1.667",
          "trans_fat": "0",
          "cholesterol": "0",
          "sodium": "533",
          "potassium": "567",
          "fiber": "10.0",
          "sugar": "3.33",
          "added_sugars": "0",
          "vitamin_d": "0",
          "vitamin_a": "0",
          "vitamin_c": "0",
          "calcium": "0",
          "iron": "0"
        }
      ]
    }
  }
}
Error Codes
CODE TYPE DESCRIPTION
2 OAuth 1.0 Missing required oauth parameter: '<details>'
3 OAuth 1.0 Unsupported oauth parameter: '<details>'
4 OAuth 1.0 Invalid signature method: '<details>'
5 OAuth 1.0 Invalid consumer key: '<details>'
6 OAuth 1.0 Invalid/expired timestamp: '<details>'
7 OAuth 1.0 Invalid/used nonce: '<details>'
8 OAuth 1.0 Invalid signature: '<details>'
9 OAuth 1.0 Invalid access token: '<details>'
13 OAuth 2.0 Invalid token: '<details>'
14 OAuth 2.0 Missing scope: '<details>'
101 Parameter Missing required parameter: '<details>'
211 Application No food item detected