Sign in | Sign up

API data with the nutrition label plugin

Tagged:

Currently contains 1 post

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.

Reply to thread