Sign in | Sign up

Advanced Food Search

What if you want to search for a grocery item, and not a restaurant item? Using the advanced search, we can set item_type=2 to search only within grocery items.

Item Type Legend

  • 1 = Restaurant
  • 2 = CPG (Grocery foods with barcodes)
  • 3 = USDA

Before we begin this more advanced tutorial, please view the following requirements.

Tutorial Requirements:
  1. Nutritionix API credentials
  2. Install and open Chrome's dev HTTP add-on
  3. Select "POST" instead of "GET"
  4. Set header as: Content-Type:application/json
  5. Check out this screenshot of what your HTTP client should look like.

Send the below POST Request to this URL: https://api.nutritionix.com/v1_1/search

{
  "appId":"YOUR_ID",
  "appKey":"YOUR_KEY",  
  "query":"Kashi",
  "fields":["item_name","brand_name","nf_calories","nf_serving_size_qty","nf_serving_size_unit"],
  "sort":{
    "field":"_score",
    "order":"desc"
  },
  "filters":{
    "item_type":2
  }
}
Response:
{
  "total": 273,
  "max_score": 2.835044,
  "hits": [
    {
      "_index": "nixproductionv12",
      "_type": "item",
      "_id": "51c53d4297c3e6efadd59e96",
      "_score": 2.835044,
      "fields": {
        "nf_serving_size_qty": 1,
        "nf_serving_size_unit": "bar",
        "item_name": "Protein & Fiber Bar, Chocolate Peanut",
        "brand_name": "Kashi",
        "nf_calories": 190
      }
    },
    {
      "_index": "nixproductionv12",
      "_type": "item",
      "_id": "51c363a297c3e69de4b03bff",
      "_score": 2.835044,
      "fields": {
        "nf_serving_size_qty": 0.5,
        "nf_serving_size_unit": "cup",
        "item_name": "Granola, Orchard Spice",
        "brand_name": "Kashi",
        "nf_calories": 220
      }
    }
  ]
}

We are only showing 2 of the example results, but you get the idea. The item ID is returned, along with the fields we selected.

Quick Start Guides 1.1 Docs Home