Sign in | Sign up

API data with the nutrition label plugin

Tagged:

Currently contains 2 posts

Avatar

April 09, 2017 09:59

gregelisara

Hi! What is the recommended way to use the nutrition label jquery plugin with API V2 data?

I’m following the usage demos here: http://dev2.nutritionix.com/html/label-jquery-plugin/demo/demo.html

Looking at the attribute names of the data provided to the plugin in the examples, they seem quite different from the attribute names that come from the API.

Here’s an example from the demo page (Example #2):

{

‘showServingUnitQuantity’ : false,
‘itemName’ : ‘Bleu Cheese Dressing’,
‘ingredientList’ : ‘Bleu Cheese Dressing’,
‘decimalPlacesForQuantityTextbox’ : 2,
‘valueServingUnitQuantity’ : 1,
‘allowFDARounding’ : true,
‘decimalPlacesForNutrition’ : 2,
‘showPolyFat’ : false,
‘showMonoFat’ : false,
‘valueCalories’ : 450,
‘valueFatCalories’ : 430,
‘valueTotalFat’ : 48,
‘valueSatFat’ : 6,
‘valueTransFat’ : 0,
‘valueCholesterol’ : 30,
‘valueSodium’ : 780,
‘valueTotalCarb’ : 3,
‘valueFibers’ : 0,
‘valueSugars’ : 3,
‘valueProteins’ : 3,
‘valueVitaminA’ : 1.22,
‘valueVitaminC’ : 4.22,
‘valueCalcium’ : 7.22,
‘valueIron’ : 11.22
}

While here is an example from the V2 API (nix_item_id 573247ff84e7f15c24fb6735):

{
“food_name”: “Chocolate Chip Cookies”,
“brand_name”: “Famous Amos Grocery”,
“serving_qty”: 1,
“serving_unit”: “package”,
“serving_weight_grams”: 56,
“nf_calories”: 280,
“nf_total_fat”: 13,
“nf_saturated_fat”: 5,
“nf_cholesterol”: 2.5,
“nf_sodium”: 200,
“nf_total_carbohydrate”: 38,
“nf_dietary_fiber”: 2,
“nf_sugars”: 18,
“nf_protein”: 3,
“nf_potassium”: null,
“nf_p”: null,
“full_nutrients”: [
{
“attr_id”: 203,
“value”: 3
},
{
“attr_id”: 204,
“value”: 13
},
{
“attr_id”: 205,
“value”: 38
},
{
“attr_id”: 208,
“value”: 280
},
{
“attr_id”: 269,
“value”: 18
},
{
“attr_id”: 291,
“value”: 2
},
{
“attr_id”: 303,
“value”: 0.36
},
{
“attr_id”: 307,
“value”: 200
},
{
“attr_id”: 601,
“value”: 2.5
},
{
“attr_id”: 606,
“value”: 5
}
],
“nix_brand_name”: “Famous Amos Grocery”,
“nix_brand_id”: “51db37b9176fe9790a898c27”,
“nix_item_name”: “Chocolate Chip Cookies”,
“nix_item_id”: “573247ff84e7f15c24fb6735”,
“metadata”: {},
“source”: 8,
“ndb_no”: null,
“tags”: null,
“alt_measures”: null,
“photo”: {
“thumb”: “https://d2eawub7utcl6.cloudfront.net/images/nix-apple-grey.png”,
“highres”: null
}

If I take the data from API, like the object above, I just get the default label. Ie.:
let dataFromAPI = {
// data as above
}
$(#label).nutritionLabel(dataFromAPI)

The label displays with default values – that is, as if the call was $(#label.nutritionLabel( )

TIA.

Avatar

August 06, 2018 04:11

Shravani

Hi, I am not getting images and individual details which is listed after Calculate Foods button.

Here are the request and response
Request
var settings = {
“async”: true,
“crossDomain”: true,
“url”: “https://trackapi.nutritionix.com/v2/natural/nutrients”,
“method”: “POST”,
“headers”: {
“content-type”: “application/json”,
“accept”: “application/json”,
“x-app-id”: “039db79f”,
“x-app-key”: “edffc89a0cc7397efe3a456d0349b798”,
“x-remote-user-id”: “0”,
“cache-control”: “no-cache”,
“postman-token”: “fa71a67a-c306-e015-1ccb-f9e7b4dd2424”
},
“processData”: false,
“data”: “{\n \”query\“: \”1 cup spinach\“,\n \”num_servings\“: 1,\n \”aggregate\“: \”string\“,\n \”line_delimited\“: false,\n \”use_raw_foods\“: false,\n \”include_subrecipe\“: false,\n \”timezone\“: \”US/Eastern\“,\n \”consumed_at\“: null,\n \”lat\“: null,\n \”lng\“: null,\n \”meal_type\“: 0,\n \”use_branded_foods\“: false,\n \”locale\“: \”en_US\“\n }”
}

$.ajax(settings).done(function (response) {
console.log(response);
});

Response
{
“foods”: [
{
“food_name”: “string”,
“brand_name”: null,
“serving_qty”: 1,
“serving_unit”: “serving”,
“serving_weight_grams”: 180,
“nf_calories”: 41.4,
“nf_total_fat”: 0.47,
“nf_saturated_fat”: 0.08,
“nf_cholesterol”: 0,
“nf_sodium”: 126,
“nf_total_carbohydrate”: 6.75,
“nf_dietary_fiber”: 4.32,
“nf_sugars”: 0.77,
“nf_protein”: 5.35,
“nf_potassium”: 838.8,
“nf_p”: 100.8,
“full_nutrients”: [
{
“attr_id”: 203,
“value”: 5.346
},
{
“attr_id”: 204,
“value”: 0.468
},
{
“attr_id”: 205,
“value”: 6.75
},
{
“attr_id”: 207,
“value”: 3.258
},
{
“attr_id”: 208,
“value”: 41.4
},
{
“attr_id”: 221,
“value”: 0
},
{
“attr_id”: 255,
“value”: 164.178
},
{
“attr_id”: 262,
“value”: 0
},
{
“attr_id”: 263,
“value”: 0
},
{
“attr_id”: 268,
“value”: 172.8
},
{
“attr_id”: 269,
“value”: 0.774
},
{
“attr_id”: 291,
“value”: 4.32
},
{
“attr_id”: 301,
“value”: 244.8
},
{
“attr_id”: 303,
“value”: 6.426
},
{
“attr_id”: 304,
“value”: 156.6
},
{
“attr_id”: 305,
“value”: 100.8
},
{
“attr_id”: 306,
“value”: 838.8
},
{
“attr_id”: 307,
“value”: 126
},
{
“attr_id”: 309,
“value”: 1.368
},
{
“attr_id”: 312,
“value”: 0.3132
},
{
“attr_id”: 313,
“value”: 68.04
},
{
“attr_id”: 315,
“value”: 1.683
},
{
“attr_id”: 317,
“value”: 2.7
},
{
“attr_id”: 318,
“value”: 18865.8
},
{
“attr_id”: 319,
“value”: 0
},
{
“attr_id”: 320,
“value”: 943.2
},
{
“attr_id”: 321,
“value”: 11318.4
},
{
“attr_id”: 322,
“value”: 0
},
{
“attr_id”: 323,
“value”: 3.744
},
{
“attr_id”: 324,
“value”: 0
},
{
“attr_id”: 328,
“value”: 0
},
{
“attr_id”: 334,
“value”: 0
},
{
“attr_id”: 337,
“value”: 0
},
{
“attr_id”: 338,
“value”: 20354.4
},
{
“attr_id”: 401,
“value”: 17.64
},
{
“attr_id”: 404,
“value”: 0.171
},
{
“attr_id”: 405,
“value”: 0.4248
},
{
“attr_id”: 406,
“value”: 0.882
},
{
“attr_id”: 410,
“value”: 0.261
},
{
“attr_id”: 415,
“value”: 0.4356
},
{
“attr_id”: 417,
“value”: 262.8
},
{
“attr_id”: 418,
“value”: 0
},
{
“attr_id”: 421,
“value”: 35.46
},
{
“attr_id”: 430,
“value”: 888.48
},
{
“attr_id”: 431,
“value”: 0
},
{
“attr_id”: 432,
“value”: 262.8
},
{
“attr_id”: 435,
“value”: 262.8
},
{
“attr_id”: 454,
“value”: 160.2
},
{
“attr_id”: 501,
“value”: 0.072
},
{
“attr_id”: 502,
“value”: 0.2286
},
{
“attr_id”: 503,
“value”: 0.2736
},
{
“attr_id”: 504,
“value”: 0.4158
},
{
“attr_id”: 505,
“value”: 0.3276
},
{
“attr_id”: 506,
“value”: 0.099
},
{
“attr_id”: 507,
“value”: 0.063
},
{
“attr_id”: 508,
“value”: 0.2412
},
{
“attr_id”: 509,
“value”: 0.2034
},
{
“attr_id”: 510,
“value”: 0.3024
},
{
“attr_id”: 511,
“value”: 0.3024
},
{
“attr_id”: 512,
“value”: 0.1188
},
{
“attr_id”: 513,
“value”: 0.2646
},
{
“attr_id”: 514,
“value”: 0.45
},
{
“attr_id”: 515,
“value”: 0.6426
},
{
“attr_id”: 516,
“value”: 0.252
},
{
“attr_id”: 517,
“value”: 0.2088
},
{
“attr_id”: 518,
“value”: 0.1926
},
{
“attr_id”: 601,
“value”: 0
},
{
“attr_id”: 605,
“value”: 0
},
{
“attr_id”: 606,
“value”: 0.0774
},
{
“attr_id”: 607,
“value”: 0
},
{
“attr_id”: 608,
“value”: 0
},
{
“attr_id”: 609,
“value”: 0
},
{
“attr_id”: 610,
“value”: 0
},
{
“attr_id”: 611,
“value”: 0
},
{
“attr_id”: 612,
“value”: 0.0108
},
{
“attr_id”: 613,
“value”: 0.0594
},
{
“attr_id”: 614,
“value”: 0.0054
},
{
“attr_id”: 617,
“value”: 0.0054
},
{
“attr_id”: 618,
“value”: 0.0306
},
{
“attr_id”: 619,
“value”: 0.1656
},
{
“attr_id”: 620,
“value”: 0
},
{
“attr_id”: 621,
“value”: 0
},
{
“attr_id”: 626,
“value”: 0.0054
},
{
“attr_id”: 627,
“value”: 0
},
{
“attr_id”: 628,
“value”: 0
},
{
“attr_id”: 629,
“value”: 0
},
{
“attr_id”: 630,
“value”: 0
},
{
“attr_id”: 631,
“value”: 0
},
{
“attr_id”: 645,
“value”: 0.0108
},
{
“attr_id”: 646,
“value”: 0.1962
}
],
“nix_brand_name”: null,
“nix_brand_id”: null,
“nix_item_name”: null,
“nix_item_id”: null,
“upc”: null,
“consumed_at”: “2018-08-06T03:59:36+00:00”,
“metadata”: {},
“source”: null,
“ndb_no”: null,
“tags”: null,
“alt_measures”: null,
“lat”: null,
“lng”: null,
“meal_type”: 0,
“photo”: {
“thumb”: “https://d2eawub7utcl6.cloudfront.net/images/nix-apple-grey.png”,
“highres”: null,
“is_user_uploaded”: false
},
“sub_recipe”: null
}
]
}

Reply to thread