Canadian Nutrient (CNF) API Guide
Table of contents
Introduction
The Canadian Nutrient File (CNF) is the standard reference food composition database reporting the amount of nutrients in foods commonly consumed in Canada.
This Application Programming Interface (API) allows developers to access that information in JSON and XML format for reuse in their own applications. The base URI for the Canadian Nutrient File Database is https://food-nutrition.canada.ca/api/canadian-nutrient-file/ and you can add parameters to it. Any requests are made relative to this URI.
Food
It contains a description and the code of each food. A food cannot be further decomposed into ingredients.
Parameters
There are three parameters in the request: id, lang and type.
Parameter | Meaning | Value | Required? | Note |
---|---|---|---|---|
api/canadian-nutrient-file/food/?id= | Returns the food according to the food code specified in the request. |
|
Yes | |
api/canadian-nutrient-file/food/?lang=en | Changes the language of the response. |
|
No, but defaults to English if not specified. | Determines whether the response is in English or French. |
api/canadian-nutrient-file/food/?type=json | Changes the format of the result. |
|
No, but defaults to JSON if not specified. | Determines whether the format of the result will be in JSON or XML. |
Foods can be accessed via these URIs:
Contents of the response
The response consists of a result that contains one or multiple objects.
Each food object consists of the following values:
Key | Value |
---|---|
food_code | The code assigned to a food. |
food_description | The complete food name. |
Sample response
{"food_code":109,"food_description":"Cheese, gouda"}
jQuery example
Example of a function that search for a food given a food code and language selection:
function getFood(id, lang) { var base = 'https://food-nutrition.canada.ca'; var uri = base + '/api/canadian-nutrient-file/food/?lang=' + lang + '&id=' + id; $.ajax({ url:uri, type:'GET', Accept:"application/json", dataType: 'json', success:function(data){ console.log(data.food_description); var frag = document.createDocumentFragment(); var h2 = document.createElement("h2"); var Food = document.createTextNode(data.food_description); var p = document.createElement("p"); var text = document.createTextNode(data.panels[0].text); h2.appendChild(Food); p.appendChild(text); frag.appendChild(h2); frag.appendChild(p); $("#responses")[0].appendChild(frag); }, error:function(error){ }, }); return; };
Nutrient Name
It contains a list of different nutrients.
Parameters
There are three parameters in the request: id, lang and type.
Parameter | Meaning | Value | Required? | Note |
---|---|---|---|---|
api/canadian-nutrient-file/nutrientname/?id= | Returns the nutrient name according to the nutrient name identification number specified in the request. |
|
Yes | |
api/canadian-nutrient-file/nutrientname/?lang=en | Changes the language of the response. |
|
No, but defaults to English if not specified. | Determines whether the response is in English or French. |
api/canadian-nutrient-file/nutrientname/?type=json | Changes the format of the result. |
|
No, but defaults to JSON if not specified. | Determines whether the format of the result will be in JSON or XML. |
Nutrient Names can be accessed via these URIs:
Contents of the response
The response consists of a result that contains one or multiple objects.
Each nutrient name object consists of the following values:
Key | Value |
---|---|
nutrient_name_id | The identification number assigned to a nutrient. |
nutrient_code | The code assigned to a nutrient. |
nutrient_symbol | The nutrient symbol or abbreviation of the nutrients. They may differ from international nomenclature. |
unit | The unit of measure (e.g., mg, g, mcg). |
nutrient_name | The name of the nutrient. |
tagname | A unique Abbreviation for a food component developed by International Network of Food Data Systems (INFOODS) to aid in the interchange of data. |
nutrient_decimals | The number of decimal places used in the rounding of the nutrient value. |
nutrient_web_order | The order to display the nutrient. |
nutrient_web_name | The name of the nutrient for the WEB. |
nutrient_group_id | The identification number of the nutrient group. |
Sample response
{"nutrient_name_id":830,"nutrient_code":696,"nutrient_symbol":"13:0","nutrient_name":"FATTY ACIDS, SATURATED, 13:0 TRIDECANOIC","unit":"g","tagname":"F13D0","nutrient_decimals":3,"nutrient_web_order":35,"nutrient_web_name":"13:0","nutrient_group_id":6}
jQuery example
Example of a function that search for a nutrient name given a nutrient name identification number and language selection:
function getNutrientName(id, lang) { var base = 'https://food-nutrition.canada.ca'; var uri = base + '/api/canadian-nutrient-file/nutrientname/?lang=' + lang + '&id=' + id; $.ajax({ url:uri, type:'GET', Accept:"application/json", dataType: 'json', success:function(data){ console.log(data.nutrient_name); var frag = document.createDocumentFragment(); var h2 = document.createElement("h2"); var NutrientName = document.createTextNode(data.nutrient_name); var p = document.createElement("p"); var text = document.createTextNode(data.panels[0].text); h2.appendChild(NutrientName); p.appendChild(text); frag.appendChild(h2); frag.appendChild(p); $("#responses")[0].appendChild(frag); }, error:function(error){ }, }); return; };
Nutrient Group
It contains a list of different nutrient group headings based on similar characteristics of the nutrients.
Parameters
There are three parameters in the request: id, lang and type.
Parameter | Meaning | Value | Required? | Note |
---|---|---|---|---|
api/canadian-nutrient-file/nutrientgroup/?id= | Returns the nutrient group according to the nutrient group identification number specified in the request. |
|
Yes | |
api/canadian-nutrient-file/nutrientgroup/?lang=en | Changes the language of the response. |
|
No, but defaults to English if not specified. | Determines whether the response is in English or French. |
api/canadian-nutrient-file/nutrientgroup/?type=json | Changes the format of the result. |
|
No, but defaults to JSON if not specified. | Determines whether the format of the result will be in JSON or XML. |
Nutrient Groups can be accessed via these URIs:
Contents of the response
The response consists of a result that contains one or multiple objects.
Each nutrient group object consists of the following values:
Key | Value |
---|---|
nutrient_group_id | The identification number assigned to a nutrient group. |
nutrient_group_name | The name of the nutrient group. |
nutrient_group_order | The order to display the nutrient group. |
Sample response
{"nutrient_group_id":1,"nutrient_group_name":"Proximates","nutrient_group_order":1}
jQuery example
Example of a function that search for a nutrient group given a nutrient group identification number and language selection:
function getNutrientGroup(id, lang) { var base = 'https://food-nutrition.canada.ca'; var uri = base + '/api/canadian-nutrient-file/nutrientgroup/?lang=' + lang + '&id=' + id; $.ajax({ url:uri, type:'GET', Accept:"application/json", dataType: 'json', success:function(data){ console.log(data.nutrient_group_name); var frag = document.createDocumentFragment(); var h2 = document.createElement("h2"); var NutrientGroup = document.createTextNode(data.nutrient_group_name); var p = document.createElement("p"); var text = document.createTextNode(data.panels[0].text); h2.appendChild(NutrientGroup); p.appendChild(text); frag.appendChild(h2); frag.appendChild(p); $("#responses")[0].appendChild(frag); }, error:function(error){ }, }); return; };
Nurient Source
It contains a list of several sources and/or types of nutrient data.
Parameters
There are three parameters in the request: id, lang and type.
Parameter | Meaning | Value | Required? | Note |
---|---|---|---|---|
api/canadian-nutrient-file/nutrientsource/?id= | Returns the nutrient source according to the nutrient source identification number specified in the request. |
|
Yes | |
api/canadian-nutrient-file/nutrientsource/?lang=en | Changes the language of the response. |
|
No, but defaults to English if not specified. | Determines whether the response is in English or French. |
api/canadian-nutrient-file/nutrientsource/?type=json | Changes the format of the result. |
|
No, but defaults to JSON if not specified. | Determines whether the format of the result will be in JSON or XML. |
Nutrient Sources can be accessed via these URIs:
Contents of the response
The response consists of a result that contains one or multiple objects.
Each nutrient source object consists of the following values:
Key | Value |
---|---|
nutrient_source_id | The identification number assigned to a nutrient source. |
nutrient_source_description | The description of the nutrient source. |
nutrient_source_code | The code that identifies a nutrient source in Canada. |
Sample response
{"nutrient_source_id":3,"nutrient_source_description":"Nutrient analyzed in a Canadian government lab","nutrient_source_code":3}
jQuery example
Example of a function that search for a nutrient source given a nutrient source identification number and language selection:
function getNutrientSource(id, lang) { var base = 'https://food-nutrition.canada.ca'; var uri = base + '/api/canadian-nutrient-file/nutrientsource/?lang=' + lang + '&id=' + id; $.ajax({ url:uri, type:'GET', Accept:"application/json", dataType: 'json', success:function(data){ console.log(data.nutrient_source_description); var frag = document.createDocumentFragment(); var h2 = document.createElement("h2"); var NutrientSource = document.createTextNode(data.nutrient_source_description); var p = document.createElement("p"); var text = document.createTextNode(data.panels[0].text); h2.appendChild(NutrientSource); p.appendChild(text); frag.appendChild(h2); frag.appendChild(p); $("#responses")[0].appendChild(frag); }, error:function(error){ }, }); return; };
Nutrient Amount
Identify the nutrient amount per 100 grams for a food.
Parameters
There are three parameters in the request: id, lang and type.
Parameter | Meaning | Value | Required? | Note |
---|---|---|---|---|
api/canadian-nutrient-file/nutrientamount/?id= | Returns the nutrient amount(s) according to the food code specified in the request. |
|
Yes | |
api/canadian-nutrient-file/nutrientamount/?lang=en | Changes the language of the response. |
|
No, but defaults to English if not specified. | Determines whether the response is in English or French. |
api/canadian-nutrient-file/nutrientamount/?type=json | Changes the format of the result. |
|
No, but defaults to JSON if not specified. | Determines whether the format of the result will be in JSON or XML. |
Nutrient Amounts can be accessed via those URIs:
Contents of the response
The response consists of a result that contains one or multiple objects.
Each nutrient amount object consists of the following values:
Key | Value |
---|---|
food_code | The code assigned to each food. |
nutrient_value | The mean value in 100g, edible portion. (The number of decimal places does not reflect the accuracy of the data). |
standard_error | The standard error of the mean. |
number_observation | The number of samples observed for the study. |
nutrient_name_id | The identification number of the nutrient. |
nutrient_web_name | The name of the nutrient for the WEB. |
nutrient_source_id | The identification number of the nutrient source. |
Sample response
[{"food_code":109,"nutrient_value":0.0,"standard_error":0,"number_observation":0,"nutrient_name_id":401,"nutrient_web_name":"Vitamin C","nutrient_source_id":4}, {"food_code":109,"nutrient_value":0.0,"standard_error":0,"number_observation":0,"nutrient_name_id":620,"nutrient_web_name":"20:4","nutrient_source_id":4}, {"food_code":109,"nutrient_value":0.0,"standard_error":0,"number_observation":0,"nutrient_name_id":221,"nutrient_web_name":"Alcohol","nutrient_source_id":0}, {"food_code":109,"nutrient_value":0.0,"standard_error":0,"number_observation":0,"nutrient_name_id":262,"nutrient_web_name":"Caffeine","nutrient_source_id":0}, {"food_code":109,"nutrient_value":0.0,"standard_error":0,"number_observation":0,"nutrient_name_id":263,"nutrient_web_name":"Theobromine","nutrient_source_id":0}, {"food_code":109,"nutrient_value":0.0,"standard_error":0,"number_observation":0,"nutrient_name_id":291,"nutrient_web_name":"Fibre, total dietary","nutrient_source_id":0}, {"food_code":109,"nutrient_value":0.0,"standard_error":0,"number_observation":0,"nutrient_name_id":431,"nutrient_web_name":"Folic acid, synthetic form","nutrient_source_id":0}, {"food_code":109,"nutrient_value":0.0,"standard_error":0,"number_observation":0,"nutrient_name_id":621,"nutrient_web_name":"22:6n-6","nutrient_source_id":0}, {"food_code":109,"nutrient_value":0.0,"standard_error":0,"number_observation":0,"nutrient_name_id":627,"nutrient_web_name":"18:4","nutrient_source_id":0}, {"food_code":109,"nutrient_value":0.0,"standard_error":0,"number_observation":0,"nutrient_name_id":628,"nutrient_web_name":"20:1","nutrient_source_id":0}, {"food_code":109,"nutrient_value":0.0,"standard_error":0,"number_observation":0,"nutrient_name_id":629,"nutrient_web_name":"20:5n-3","nutrient_source_id":0}, {"food_code":109,"nutrient_value":0.0,"standard_error":0,"number_observation":0,"nutrient_name_id":630,"nutrient_web_name":"22:1","nutrient_source_id":0}, {"food_code":109,"nutrient_value":0.0,"standard_error":0,"number_observation":0,"nutrient_name_id":631,"nutrient_web_name":"22:5n-3","nutrient_source_id":0}, {"food_code":109,"nutrient_value":0.0,"standard_error":0,"number_observation":0,"nutrient_name_id":827,"nutrient_web_name":"20:3","nutrient_source_id":12}, {"food_code":109,"nutrient_value":0.0,"standard_error":0,"number_observation":0,"nutrient_name_id":832,"nutrient_web_name":"18:3n6cccn-6","nutrient_source_id":12}, {"food_code":109,"nutrient_value":0.0,"standard_error":0,"number_observation":0,"nutrient_name_id":834,"nutrient_web_name":"Alpha carotene","nutrient_source_id":0}, {"food_code":109,"nutrient_value":0.0,"standard_error":0,"number_observation":0,"nutrient_name_id":835,"nutrient_web_name":"Beta cryptozanthin","nutrient_source_id":0}, {"food_code":109,"nutrient_value":0.0,"standard_error":0,"number_observation":0,"nutrient_name_id":836,"nutrient_web_name":"Lycopene","nutrient_source_id":0}, {"food_code":109,"nutrient_value":0.0,"standard_error":0,"number_observation":0,"nutrient_name_id":837,"nutrient_web_name":"Lutein and zeaxanthin","nutrient_source_id":0}, {"food_code":109,"nutrient_value":0.0,"standard_error":0,"number_observation":0,"nutrient_name_id":854,"nutrient_web_name":"20:3n-6","nutrient_source_id":12}, {"food_code":109,"nutrient_value":0.0,"standard_error":0,"number_observation":0,"nutrient_name_id":855,"nutrient_web_name":"20:4n-6","nutrient_source_id":12}, {"food_code":109,"nutrient_value":0.0,"standard_error":0,"number_observation":0,"nutrient_name_id":861,"nutrient_web_name":"20:3n-3","nutrient_source_id":12}, {"food_code":109,"nutrient_value":0.0,"standard_error":0,"number_observation":0,"nutrient_name_id":840,"nutrient_web_name":"22:1c","nutrient_source_id":12}, {"food_code":109,"nutrient_value":0.0,"standard_error":0,"number_observation":0,"nutrient_name_id":852,"nutrient_web_name":"22:1t","nutrient_source_id":12}, {"food_code":109,"nutrient_value":0.011,"standard_error":0,"number_observation":0,"nutrient_name_id":315,"nutrient_web_name":"Manganese, Mn","nutrient_source_id":0}, {"food_code":109,"nutrient_value":0.03,"standard_error":0,"number_observation":1,"nutrient_name_id":404,"nutrient_web_name":"Thiamin","nutrient_source_id":0, {"food_code":109,"nutrient_value":0.036,"standard_error":0,"number_observation":0,"nutrient_name_id":312,"nutrient_web_name":"Copper, Cu","nutrient_source_id":0}, {"food_code":109,"nutrient_value":0.063,"standard_error":0,"number_observation":10,"nutrient_name_id":406,"nutrient_web_name":"Niacin","nutrient_source_id":0}, {"food_code":109,"nutrient_value":0.08,"standard_error":0,"number_observation":20,"nutrient_name_id":415,"nutrient_web_name":"Vitamin B-6","nutrient_source_id":0}, {"food_code":109,"nutrient_value":0.207,"standard_error":0,"number_observation":0,"nutrient_name_id":825,"nutrient_web_name":"18:2n6cc","nutrient_source_id":4}, {"food_code":109,"nutrient_value":0.207,"standard_error":0,"number_observation":0,"nutrient_name_id":869,"nutrient_web_name":"Fatty acids, polyunsaturated, total omega n-6","nutrient_source_id":2}, {"food_code":109,"nutrient_value":0.24,"standard_error":0,"number_observation":0,"nutrient_name_id":323,"nutrient_web_name":"Tocopherol, alpha","nutrient_source_id":0}]
jQuery example
Example of a function that search for nutrient amount(s) given a food code and language selection:
function getNutrientAmount(id, lang) { var base = 'https://food-nutrition.canada.ca'; var uri = base + '/api/canadian-nutrient-file/nutrientamount/?lang=' + lang + '&id=' + id; $.ajax({ url:uri, type:'GET', Accept:"application/json", dataType: 'json', success:function(data){ console.log(data.nutrient_web_name); var frag = document.createDocumentFragment(); var h2 = document.createElement("h2"); var NutrientAmount = document.createTextNode(data.nutrient_web_name); var p = document.createElement("p"); var text = document.createTextNode(data.panels[0].text); h2.appendChild(NutrientAmount); p.appendChild(text); frag.appendChild(h2); frag.appendChild(p); $("#responses")[0].appendChild(frag); }, error:function(error){ }, }); return; };
Serving Size
Measures and conversion factors per food. The conversion factors are food specific multipliers by which the nutrient values for each food may be multiplied to give the nutrients in described portions.
Parameters
There are three parameters in the request: id, lang and type.
Parameter | Meaning | Value | Required? | Note |
---|---|---|---|---|
api/canadian-nutrient-file/servingsize/?id= | Returns serving size(s) according to the food code specified in the request. |
|
Yes | |
api/canadian-nutrient-file/servingsize/?lang=en | Changes the language of the response. |
|
No, but defaults to English if not specified. | Determines whether the response is in English or French. |
api/canadian-nutrient-file/servingsize/?type=json | Changes the format of the result. |
|
No, but defaults to JSON if not specified. | Determines whether the format of the result will be in JSON or XML. |
Serving sizes can be accessed via these URIs:
Contents of the response
The response consists of a result that contains one or multiple objects.
Each serving size object consists of the following values:
Key | Value |
---|---|
food_code | The code assigned to each food. |
food_description | The complete food name. |
conversion_factor_value | The factor by which one would multiply the nutrient per 100g to obtain nutrient amounts per the measure described. |
measure_name | The measure description. |
Sample response
[{"conversion_factor_value":0.5,"food_code":20,"food_description":"Cheese, brie","measure_name":"50g"}, {"conversion_factor_value":1.01437,"food_code":20,"food_description":"Cheese, brie","measure_name":"100ml melted"}, {"conversion_factor_value":2.53593,"food_code":20,"food_description":"Cheese, brie","measure_name":"250ml melted"}, {"conversion_factor_value":0.60862,"food_code":20,"food_description":"Cheese, brie","measure_name":"100ml slices"}, {"conversion_factor_value":1.52156,"food_code":20,"food_description":"Cheese, brie","measure_name":"250ml slices"}]
jQuery example
Example of a function that search for serving size(s) given a food code and language selection:
function getServingSize(id, lang) { var base = 'https://food-nutrition.canada.ca'; var uri = base + '/api/canadian-nutrient-file/servingsize/?lang=' + lang + '&id=' + id; $.ajax({ url:uri, type:'GET', Accept:"application/json", dataType: 'json', success:function(data){ console.log(data.conversion_factor_value); var frag = document.createDocumentFragment(); var h2 = document.createElement("h2"); var ServingSize = document.createTextNode(data.conversion_factor_value); var p = document.createElement("p"); var text = document.createTextNode(data.panels[0].text); h2.appendChild(ServingSize); p.appendChild(text); frag.appendChild(h2); frag.appendChild(p); $("#responses")[0].appendChild(frag); }, error:function(error){ }, }); return; };
Refuse Amount
Refuse amount is the percent of refuse, or inedible portion, for each food.
Parameters
There are three parameters in the request: id, lang and type.
Parameter | Meaning | Value | Required? | Note |
---|---|---|---|---|
api/canadian-nutrient-file/refuseamount/?id= | Returns refuse amount(s) according to the food code specified in the request. |
|
Yes | |
api/canadian-nutrient-file/refuseamount/?lang=en | Changes the language of the response. |
|
No, but defaults to English if not specified. | Determines whether the response is in English or French. |
api/canadian-nutrient-file/refuseamount/?type=json | Changes the format of the result. |
|
No, but defaults to JSON if not specified. | Determines whether the format of the result will be in JSON or XML. |
Refuse Amounts can be accessed via these URIs:
Contents of the response
The response consists of a result that contains one or multiple objects.
Each refuse amount object consists of the following values:
Key | Value |
---|---|
food_code | The code assigned to each food. |
food_description | The complete food name. |
refuse_amount | The percent refuse. |
refuse_name | The refuse description. |
Sample response
{"refuse_amount":0.0,"food_code":20,"food_description":"Cheese, brie","measure_name":"total refuse"}
jQuery example
Example of a function that search for refuse amount(s) given a food code and language selection:
function getRefuse(id, lang) { var base = 'https://food-nutrition.canada.ca'; var uri = base + '/api/canadian-nutrient-file/refuseamount/?lang=' + lang + '&id=' + id; $.ajax({ url:uri, type:'GET', Accept:"application/json", dataType: 'json', success:function(data){ console.log(data.food_description); var frag = document.createDocumentFragment(); var h2 = document.createElement("h2"); var Refuse = document.createTextNode(data.food_description); var p = document.createElement("p"); var text = document.createTextNode(data.panels[0].text); h2.appendChild(Refuse); p.appendChild(text); frag.appendChild(h2); frag.appendChild(p); $("#responses")[0].appendChild(frag); }, error:function(error){ }, }); return; };
Yield Amount
Contains the yield from refuse and/or cooking losses assigned to certain foods. These yields are most often used for food inventory purposes.
Parameters
There are three parameters in the request: id, lang and type.
Parameter | Meaning | Value | Required? | Note |
---|---|---|---|---|
api/canadian-nutrient-file/yieldamount/?id= | Returns yield amount according to the food code specified in the request. |
|
Yes | |
api/canadian-nutrient-file/yieldamount/?lang=en | Changes the language of the response. |
|
No, but defaults to English if not specified. | Determines whether the response is in English or French. |
api/canadian-nutrient-file/yieldamount/?type=json | Changes the format of the result. |
|
No, but defaults to JSON if not specified. | Determines whether the format of the result will be in JSON or XML. |
Yield Amounts can be accessed via these URIs:
Contents of the response
The response consists of a result that contains one or multiple objects.
Each yield amount object consists of the following values:
Key | Value |
---|---|
food_code | The code assigned to each food. |
food_description | The complete food name. |
yield_amount | The yield from refuse and/or cooking losses. |
yield_name | The yield description. |
Sample response
{"yield_amount":1.318,"food_code":57,"food_description":"Dessert topping (non dairy), powdered","measure_name":"amount to make 15ml"}
jQuery example
Example of a function that search for yield amounts given a food code and language selection:
function getYield(id, lang) { var base = 'https://food-nutrition.canada.ca'; var uri = base + '/api/canadian-nutrient-file/yieldamount/?lang=' + lang + '&id=' + id; $.ajax({ url:uri, type:'GET', Accept:"application/json", dataType: 'json', success:function(data){ console.log(data.yield_amount); var frag = document.createDocumentFragment(); var h2 = document.createElement("h2"); var Yield = document.createTextNode(data.yield_amount); var p = document.createElement("p"); var text = document.createTextNode(data.panels[0].text); h2.appendChild(Yield); p.appendChild(text); frag.appendChild(h2); frag.appendChild(p); $("#responses")[0].appendChild(frag); }, error:function(error){ }, }); return; };