fatsecret Platform API Documentation
Foods: Find Id For Barcode
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 2?
We are introducing version 2 to return the matched food (and associated nutrional information) of the barcode instead of the food_id. This will return the same response as food.get.v5 with the food_id or return with error code 211.
Parameters
URL / Method
NAME | TYPE | REQUIRED | DESCRIPTION |
---|---|---|---|
URL (new) Method |
N/A | Required | "https://platform.fatsecret.com/rest/food/barcode/find-by-id/v2" HTTP "GET" |
OR | |||
method | String | Required | "food.find_id_for_barcode.v2" (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_sub_categories | Boolean | Optional | Response will include the names of all sub categories associated with the food |
include_food_images | Boolean | Optional | Response will include food image in the response. (Requires separate premier offering, please contact us in order for this feature to be enabled for your account) |
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"). |
Response
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 | Long | 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). Eg. 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 | Long | Preference name (English only). Values include Vegan, Vegetarian |
value | Ternary | Preference value. Valid values are 1 (True), 0 (False) and -1 (Unknown). Eg. Vegan: 1 (Is vegan), 0 (Is not vegan), -1 (Unknown) |
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". Please note that this is only applicable for when food_type is "Generic" whereas for "Brand" the number of units will always be "1" |
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". Please note that this is only applicable for when food_type is "Generic" whereas for "Brand" the measurement description will always be "serving" |
is_default | Int | (Premier Exclusive) Only included if its 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>
<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"
}
]
}
},
"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 |