Skip to content

Instantly share code, notes, and snippets.

@mattsilv
Last active November 17, 2023 10:49
Show Gist options
  • Save mattsilv/478c9288f213ce5333399a41bd6da5a4 to your computer and use it in GitHub Desktop.
Save mattsilv/478c9288f213ce5333399a41bd6da5a4 to your computer and use it in GitHub Desktop.
Nutritionix API v2 - Example GET Request to /search/item Endpoint

GET https://trackapi.nutritionix.com/v2/search/item?nix_item_id=513fc9e73fe3ffd40300109f

HEADERS required:

  • x-app-id
  • x-app-key

Response body:

{
  "foods": [
    {
      "food_name": "Big Mac",
      "brand_name": "McDonald's",
      "serving_qty": 7.5,
      "serving_unit": "oz",
      "serving_weight_grams": null,
      "nf_calories": 540,
      "nf_total_fat": 28,
      "nf_saturated_fat": 10,
      "nf_cholesterol": 80,
      "nf_sodium": 970,
      "nf_total_carbohydrate": 47,
      "nf_dietary_fiber": 3,
      "nf_sugars": 9,
      "nf_protein": 25,
      "nf_potassium": null,
      "nf_p": null,
      "full_nutrients": [
        {
          "attr_id": 203,
          "value": 25
        },
        {
          "attr_id": 204,
          "value": 28
        },
        {
          "attr_id": 205,
          "value": 47
        },
        {
          "attr_id": 208,
          "value": 540
        },
        {
          "attr_id": 269,
          "value": 9
        },
        {
          "attr_id": 291,
          "value": 3
        },
        {
          "attr_id": 301,
          "value": 250
        },
        {
          "attr_id": 303,
          "value": 4.5
        },
        {
          "attr_id": 307,
          "value": 970
        },
        {
          "attr_id": 318,
          "value": 300
        },
        {
          "attr_id": 401,
          "value": 1.2
        },
        {
          "attr_id": 601,
          "value": 80
        },
        {
          "attr_id": 606,
          "value": 10
        }
      ],
      "nix_brand_name": "McDonald's",
      "nix_brand_id": "513fbc1283aa2dc80c000053",
      "nix_item_name": "Big Mac",
      "nix_item_id": "513fc9e73fe3ffd40300109f",
      "metadata": {},
      "source": 8,
      "ndb_no": null,
      "tags": null,
      "alt_measures": null,
      "photo": {
        "thumb": "https://d2eawub7utcl6.cloudfront.net/images/nix-apple-grey.png",
        "highres": null
      }
    }
  ]
}
@shravanipl
Copy link

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
}
]
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment