๐Ÿ‡ง๐Ÿ‡ช Delhaize Example solution JavaScript /suggest + /products

Plan a Keto Week at Delhaize โ€” Seven Dinners, One Script

This builds a keto dinner plan for the week by using Pepesto's /suggest endpoint to find low-carb recipes, then pricing each at Delhaize via /products. The output is a per-meal shopping list with estimated cost and any substituted items flagged.

Run this yourself

$ PEPESTO_API_KEY=your_key node delhaize-keto-week-meal-plan.js

Full script: delhaize-keto-week-meal-plan.js. You'll need an API key to run it โ€” get one here.

Getting started

If you have already checked out the GitHub repository:

bash
export PEPESTO_API_KEY=your_key_here
node delhaize-keto-week-meal-plan.js

The first call โ€” finding seven keto dinners

The /suggest endpoint accepts a free-text query. Put your dietary constraints directly in the query string โ€” the response is a list of recipes, each with a kg_token encoding the entire ingredient graph.

js
// /suggest returns 3 recipes per call, so several queries are needed to fill a
// week. The same dish can come back from two queries โ€” and even twice within a
// single call โ€” with a different kg_token each time, so duplicates have to be
// dropped by title. Each query pulls on a different protein to spread the week.
async function suggestKetoMeals(target = 7) {
  console.log('Searching for keto dinner recipes...');
  const queries = [
    'Keto chicken dinner, low carb and high protein',
    'Keto beef or steak dinner, low carb and high protein',
    'Keto salmon or white fish dinner, low carb and high protein',
    'Keto pork or lamb dinner, low carb and high protein',
  ];

  const suggestions = await Promise.all(queries.map(async (query) => {
    const response = await fetch(`${BASE_URL}/suggest`, {
      method: 'POST',
      headers,
      body: JSON.stringify({ query }),
    });

    const text = await response.text();

    if (!response.ok) {
      throw new Error(`/suggest failed: ${response.status} ${text}`);
    }

    return JSON.parse(text);
  }));

  const seen = new Set();
  const unique = [];
  for (const recipe of suggestions.flatMap((s) => s.recipes)) {
    const key = recipe.title.trim().toLowerCase();
    if (seen.has(key)) continue;
    seen.add(key);
    unique.push(recipe);
  }

  if (unique.length < target) {
    console.log(`Only ${unique.length} distinct dinners came back โ€” planning for those.`);
  }

  return unique.slice(0, target);
}

Each call returns three recipes with titles, ingredient lists, nutrition data, and a kg_token per recipe:

json โ€” /suggest response (excerpt)
{
  "recipes": [
    {
      "title": "Greek-style baked fish with tomatoes and cheese",
      "ingredients": [
        "2 tomatoes (~350g)",
        "3 garlic cloves",
        "15g spring onions",
        "parsley",
        "150g parmesan cheese",
        "200ml sour cream",
        "700g fish fillets",
        "salt",
        "black pepper"
      ],
      "nutrition": {
        "calories": 1883,
        "carbohydrates_grams": 25,
        "protein_grams": 190,
        "fat_grams": 91
      },
      "kg_token": "EjEKL0dyZWVrLXN0eWxlIGJh..."
    },
    {
      "title": "Baked salmon with cream cheese crust",
      "ingredients": [
        "600g salmon fillets",
        "150g cream cheese",
        "2 tbsp lemon juice",
        "fresh dill",
        "2 garlic cloves",
        "black pepper",
        "salt"
      ],
      "nutrition": {
        "calories": 1540,
        "carbohydrates_grams": 8,
        "protein_grams": 142,
        "fat_grams": 98
      },
      "kg_token": "EjIKMEJha2Vk..."
    }
  ]
}

The second call โ€” resolving ingredients to Delhaize products

I take all seven kg_token values and pass them in a single /products call with supermarket_domain: "delhaize.be". The API returns the best-matching Delhaize SKU for every ingredient across all seven recipes.

js
async function getDelhaizeProducts(kgTokens) {
  console.log(`Fetching Delhaize products for ${kgTokens.length} recipes...`);
  const res = await fetch(`${BASE_URL}/products`, {
    method: 'POST',
    headers,
    body: JSON.stringify({
      recipe_kg_tokens: kgTokens,
      supermarket_domain: 'delhaize.be',
    }),
  });
  if (!res.ok) throw new Error(`/products failed: ${res.status}`);
  return res.json();
}
json โ€” /products response (excerpt)
{
  "items": [
    {
      "item_name": "Fish fillets",
      "products": [
        {
          "product": {
            "product_name": "Delhaize MSC Cod Fillets",
            "quantity": { "grams": 400 },
            "price": { "price": 699, "promotion": { "promo": true } }
          },
          "session_token": "eyJwcm9kdWN0...",
          "num_units_to_buy": 2
        }
      ]
    },
    {
      "item_name": "Parmesan cheese",
      "products": [
        {
          "product": {
            "product_name": "Grana Padano Delhaize 200g",
            "quantity": { "grams": 200 },
            "price": { "price": 389, "promotion": {} }
          },
          "session_token": "eyJwcm9kdWN0...",
          "num_units_to_buy": 1
        }
      ]
    },
    {
      "item_name": "Gouda cheese",
      "products": [
        {
          "product": {
            "product_name": "Delhaize Gouda | Cheese cubes | Young",
            "quantity": { "grams": 120 },
            "price": { "price": 229, "promotion": {} },
            "substitution": true
          },
          "session_token": "eyJwcm9kdWN0...",
          "num_units_to_buy": 1
        }
      ]
    }
  ]
}

What the data showed

The full week of seven dinners came to 47 unique Delhaize line items. Three things are worth noting. First, the API flagged two items as substitutions โ€” it couldn't find an exact match for "sour cream" and returned Delhaize Crรจme Fraรฎche instead. That's close enough for keto, but the flag is useful to know.

Second, seven items were on promotion that week, including the Delhaize MSC Cod Fillets and Delhaize Serrano ham rolls with cream cheese. The promo: true flag is directly in the response, so it's trivial to surface those.

Third, the ingredient de-duplication is excellent. Three recipes called for garlic; the API consolidated them into one line item with num_units_to_buy: 2 rather than listing garlic three times.

The result

A weekly meal plan is now a three-second script. Run it Friday evening, review the list, and place the Delhaize order. The session tokens from the /products response go straight into /api/session to create a checkout link.

What else you could do?

Add a budget cap: if the week's total exceeds โ‚ฌ80, swap the most expensive recipe for a cheaper one and re-run /products. Add a cache so recurring ingredients (olive oil, salt, garlic) are only re-checked when the price changes. Add a weekly HTML email summary to make the whole workflow fully automated.

Links

Ready to build?

Start building keto shopping lists at Delhaize

Use /suggest to generate keto recipes and /products to price them at Delhaize โ€” two endpoints, one key.

27supermarkets 13countries 1schema Instant access