# Product Lookup Edge Function Fetches product data from Open Food Facts API by barcode and caches results in the database. ## Endpoint `POST /functions/v1/product-lookup` ## Request ```json { "barcode": "8000500310427" } ``` ## Response ### Success (200) ```json { "barcode": "8000500310427", "name": "Nutella", "brand": "Ferrero", "quantity": "750g", "image_url": "https://...", "category": "spreads", "cached": false } ``` ### Not Found (404) ```json { "barcode": "1234567890123", "name": "Unknown Product (1234567890123)", "cached": false } ``` ### Error (500) ```json { "error": "Error message", "barcode": null, "name": null } ``` ## Features - ✅ Queries Open Food Facts API - ✅ Caches results in `products` table - ✅ Returns cached data for subsequent requests - ✅ Handles product not found gracefully - ✅ CORS enabled for frontend access ## Environment Variables - `SUPABASE_URL`: Auto-injected by Supabase - `SUPABASE_SERVICE_ROLE_KEY`: Auto-injected by Supabase ## Testing ```bash # Local (with Supabase CLI) supabase functions serve product-lookup # Test request curl -X POST http://localhost:54321/functions/v1/product-lookup \ -H "Content-Type: application/json" \ -H "Authorization: Bearer YOUR_ANON_KEY" \ -d '{"barcode":"8000500310427"}' ``` ## Deployment ```bash supabase functions deploy product-lookup ```