Skip to Content
ToolsFood lookup

Food lookup

ctx.FOOD finds packaged food in Open Food Facts, from the digits on a barcode or the name on the label.

Methods

MethodInputReturns
lookupBarcode{ barcode }One product, or null
search{ name }Up to three matching products

Returns

{ barcode: "6001275000013", name: "Jungle Oats", brand: "Jungle", servingSize: "40 g", per100g: { kcal: 368, protein: 12, carbs: 60, sugar: 1, fat: 8, saturatedFat: 1.4, fibre: 10, salt: 0 }, perServing: { kcal: 147, protein: 4.8, carbs: 24, sugar: 0.4, fat: 3.2, saturatedFat: 0.6, fibre: 4, salt: 0 }, allergens: ["gluten"], nutriScore: "A", read: "Jungle Oats has 147 kcal per 40 g serving. Contains gluten.", }

read is one or two plain sentences a loop can send as they are. Any nutrient can be null when the label doesn’t give it.

Use it

import { workflow } from "@loops/sdk"; type Barcode = { barcode: string }; export const foodWorkflow = workflow<Barcode>({ id: "food-lookup", execute: async ({ step, event }) => step.do("Look up the product", ({ ctx }) => ctx.FOOD.lookupBarcode({ barcode: event.body.barcode }), ), });

What it won’t invent

Home-cooked food isn’t in the database, so an empty result is the expected answer there. Any figures a loop gives instead are an estimate, and it should say so.

Last updated on