Developer Guide
Recipe to Shopping List API: Build Shoppable Grocery Lists
Shopping lists fail when recipe ingredients are plain text strings. Recipe API links every ingredient across 25,000+ recipes to a stable UUID, structured quantity, unit, preparation note, and substitutions — making deduplication, aisle grouping, and retail SKU mapping straightforward.
1. What the API returns for every ingredient
On GET /api/v1/recipes/{id}, ingredients are grouped by dish component and every line item carries a typed quantity, unit, preparation, substitutions, and a canonical ingredient_id.
{
"group_name": "Chili Base",
"items": [
{
"name": "stewing beef",
"quantity": 910,
"unit": "g",
"preparation": "cut into 1.3cm (1/2 inch) cubes",
"notes": null,
"substitutions": [],
"ingredient_id": "09f2eef4-739a-4fca-8b63-97d697257990",
"nutrition_source": "USDA FoodData Central"
},
{
"name": "garlic",
"quantity": 2,
"unit": null,
"preparation": "peeled",
"notes": "about 6g",
"substitutions": [],
"ingredient_id": "30109e1e-d8e8-4f76-a6f4-82ac5b071fde",
"nutrition_source": "USDA FoodData Central"
},
{
"name": "salt",
"quantity": null,
"unit": null,
"preparation": null,
"notes": "to taste",
"substitutions": [],
"ingredient_id": "2631739c-2de4-4389-a6e3-ed3d06d0406f",
"nutrition_source": "USDA FoodData Central"
}
]
}2. Search ingredients, map aisles, and filter by pantry
Use GET /api/v1/ingredients to search the 10,000+ ingredient catalogue and GET /api/v1/ingredient-categories for the 23 canonical aisle categories. Pass those same UUIDs back into GET /api/v1/recipes?ingredients=... for pantry matching or cart cross-sell.
# 1. Look up canonical ingredient UUIDs (1 request per search) curl -s "https://recipe-api.com/api/v1/ingredients?q=chickpeas&per_page=5" \ -H "X-API-Key: $RECIPE_API_KEY" # 2. Fetch aisle categories for grouping your grocery list (1 request) curl -s "https://recipe-api.com/api/v1/ingredient-categories" \ -H "X-API-Key: $RECIPE_API_KEY" # 3. Find recipes containing ALL specified pantry/cart ingredient UUIDs (1 request) curl -s "https://recipe-api.com/api/v1/recipes?ingredients=693538c2-09f5-4a24-9460-0d968be35a2f,30109e1e-d8e8-4f76-a6f4-82ac5b071fde" \ -H "X-API-Key: $RECIPE_API_KEY"
3. Handle real-world aggregation edge cases
Merging across recipes is reliable when you group by (ingredient_id, unit) and keep unquantified staples separate:
Swipe table horizontally →
| Ingredient shape | Shopping-list rule | Why it matters |
|---|---|---|
quantity: number, unit: 'g' | 'ml' | Sum by (ingredient_id, unit) | Metric weights and volumes add cleanly across recipes without string matching. |
quantity: number, unit: null | Count-based item (e.g., 2 bay leaves, 6 chilies) | Key by (ingredient_id, 'count') and check notes (e.g., 'about 30g') when mapping to retail pack sizes. |
quantity: null, notes: 'to taste' | Pantry / seasoning list | Keep unquantified staples separate so you never display 'NaN salt' in a cart. |
preparation: 'diced' vs 'whole' | Preserve preparation notes on the line item | You buy one bunch of garlic at the store, then show per-recipe prep notes when cooking. |
GET /api/v1/ingredients/{id} | category (23 canonical aisles) + per_100g nutrition | Map each ingredient_id to its grocery category (Produce, Legumes, Dairy, Spices) or your retailer's SKU catalog. |
4. Runnable Node.js shopping-list merger
Download shopping-list.mjs, set RECIPE_API_KEY in your server environment, and run node shopping-list.mjs on Node.js 22+. It makes 3 requests (1 search + 2 recipe lookups) and prints a deduplicated grocery list.
// Node.js 22+. Keep RECIPE_API_KEY on your server, never in browser code.
// Fetches 2 dinner recipes (1 search + 2 detail calls = 3 requests) and
// merges their ingredients by stable ingredient_id + unit into a shopping list.
import { pathToFileURL } from "node:url";
export function mergeShoppingList(recipes) {
const merged = new Map();
const pantryNotes = [];
for (const recipe of recipes) {
for (const group of recipe.ingredients ?? []) {
for (const item of group.items ?? []) {
const id = item.ingredient_id ?? item.name.toLowerCase();
// Keep unquantified items ("to taste") separate from summed amounts.
if (item.quantity == null) {
pantryNotes.push({
ingredient_id: item.ingredient_id ?? null,
name: item.name,
notes: item.notes ?? "as needed",
recipe: recipe.name,
});
continue;
}
const unitKey = item.unit ?? "count";
const key = `${id}::${unitKey}`;
const existing = merged.get(key);
if (existing) {
existing.quantity = Math.round((existing.quantity + item.quantity) * 100) / 100;
if (!existing.recipes.includes(recipe.name)) existing.recipes.push(recipe.name);
if (item.preparation && !existing.preparations.includes(item.preparation)) {
existing.preparations.push(item.preparation);
}
} else {
merged.set(key, {
ingredient_id: item.ingredient_id ?? null,
name: item.name,
quantity: item.quantity,
unit: item.unit,
preparations: item.preparation ? [item.preparation] : [],
recipes: [recipe.name],
});
}
}
}
}
return {
items: [...merged.values()].sort((a, b) => a.name.localeCompare(b.name)),
pantry_notes: pantryNotes,
};
}
export async function shoppingListExample(apiKey, fetcher = fetch) {
if (!apiKey) throw new Error("Set RECIPE_API_KEY to your own API key.");
async function get(path) {
const response = await fetcher(`https://recipe-api.com/api/v1/${path}`, {
headers: { "X-API-Key": apiKey },
signal: AbortSignal.timeout(30_000),
});
if (!response.ok) {
const retry = response.headers.get("Retry-After");
throw new Error(
`Recipe API returned ${response.status}.${
retry ? ` Retry after ${retry} seconds.` : " Check your key and remaining allowance."
}`,
);
}
return response.json();
}
const query = new URLSearchParams({
category: "Dinner",
max_calories: "650",
per_page: "2",
});
const search = await get(`recipes?${query}`);
if (!Array.isArray(search.data) || !search.data.length) {
return { recipes: [], shopping_list: { items: [], pantry_notes: [] } };
}
const details = [];
for (const summary of search.data) {
const detail = await get(`recipes/${encodeURIComponent(summary.id)}`);
details.push(detail.data);
}
return {
recipes: details.map((r) => ({ id: r.id, name: r.name, yields: r.meta?.yields ?? null })),
shopping_list: mergeShoppingList(details),
};
}
if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
try {
console.log(JSON.stringify(await shoppingListExample(process.env.RECIPE_API_KEY), null, 2));
} catch (error) {
console.error(error.message);
process.exitCode = 1;
}
}
Check plan rights and caching limits before persisting ingredient catalogs or recipes in a commercial grocery app.
Frequently asked questions
Related guides
Build shoppable recipes on clean entities
Test the ingredient endpoints and download the shopping-list script with a free evaluation key — 50 requests, no card.