Food

The Food API allows you to access Macrofy's massive database of over 3.9 million nutrition items. On this page, we'll dive into the endpoints for searching food by text and resolving barcodes.

The food model

The food model contains all the nutritional information, serving sizes, and metadata about a specific product or ingredient.

Properties

  • Name
    id
    Type
    string
    Description

    Unique identifier for the food item.

  • Name
    name
    Type
    string
    Description

    The name of the food item (e.g. "Chicken Breast").

  • Name
    brand
    Type
    string
    Description

    Optional brand name for the food item.

  • Name
    barcode
    Type
    string
    Description

    The UPC/EAN barcode associated with the food item, if applicable.

  • Name
    servingSize
    Type
    object
    Description

    Contains the value, unit, and optional label for the serving size.

  • Name
    macros
    Type
    object
    Description

    Contains macronutrient and micronutrient data (energy, protein, fat, carbohydrates, etc.) scaled to the servingSize.

  • Name
    source
    Type
    string
    Description

    The origin of the data (open_food_facts, spike_api, or manual_entry).

  • Name
    created_at
    Type
    string
    Description

    Timestamp of when the food item was added to the database.


GET/v1/foods/search

Search foods

Perform a full-text, ranked search across the food database. The search intelligently handles partial matches, fuzzy matching, and name prioritization.

Optional attributes

  • Name
    q
    Type
    string
    Description

    The search query. Note: Queries shorter than 2 characters will return an empty array without performing a search.

  • Name
    limit
    Type
    number
    Description

    The maximum number of results to return. Defaults to 20.

Request

GET
/v1/foods/search?q=chicken&limit=5
curl -G https://api.macrofy.com/v1/foods/search \
  -H "Authorization: Bearer {token}" \
  -d q="chicken" \
  -d limit=5

Response

[
  {
    "id": "123e4567-e89b-12d3-a456-426614174000",
    "name": "Chicken Breast",
    "servingSize": {
      "value": 100,
      "unit": "g"
    },
    "macros": {
      "energy": 165,
      "protein": 31,
      "fat": 3.6,
      "carbohydrates": 0
    },
    "source": "open_food_facts",
    "createdAt": "2025-01-01T00:00:00Z",
    "updatedAt": "2025-01-01T00:00:00Z"
  }
]

GET/v1/foods/barcode/:upc

Resolve barcode

Look up a food item by its UPC, EAN-13, or GTIN-14 barcode.

This endpoint uses a smart resolution layer: if a user scans a barcode in one format (e.g. EAN-13) but the database stores it in another (e.g. UPC-A), the API will automatically generate and check all standard GS1 format candidates to find a match.

Returns a 404 error if the barcode cannot be found.

Request

GET
/v1/foods/barcode/012345678905
curl https://api.macrofy.com/v1/foods/barcode/012345678905 \
  -H "Authorization: Bearer {token}"

Response

{
  "id": "123e4567-e89b-12d3-a456-426614174000",
  "name": "Chicken Breast",
  "barcode": "012345678905",
  "servingSize": {
    "value": 100,
    "unit": "g"
  },
  "macros": {
    "energy": 165,
    "protein": 31,
    "fat": 3.6,
    "carbohydrates": 0
  },
  "source": "open_food_facts",
  "createdAt": "2025-01-01T00:00:00Z",
  "updatedAt": "2025-01-01T00:00:00Z"
}

Was this page helpful?