Some checks failed
Deploy to Coolify / Code Quality (pull_request) Has been cancelled
Deploy to Coolify / Run Tests (pull_request) Has been cancelled
Deploy to Coolify / Deploy to Development (pull_request) Has been cancelled
Deploy to Coolify / Deploy to Production (pull_request) Has been cancelled
Deploy to Coolify / Deploy to Test (pull_request) Has been cancelled
Pull Request Checks / Validate PR (pull_request) Has been cancelled
- Fetch product data from Open Food Facts API - Cache results in products table - Handle product not found gracefully - CORS enabled for frontend access - Returns cached data for performance Closes #24
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
{
"barcode": "8000500310427"
}
Response
Success (200)
{
"barcode": "8000500310427",
"name": "Nutella",
"brand": "Ferrero",
"quantity": "750g",
"image_url": "https://...",
"category": "spreads",
"cached": false
}
Not Found (404)
{
"barcode": "1234567890123",
"name": "Unknown Product (1234567890123)",
"cached": false
}
Error (500)
{
"error": "Error message",
"barcode": null,
"name": null
}
Features
- ✅ Queries Open Food Facts API
- ✅ Caches results in
productstable - ✅ Returns cached data for subsequent requests
- ✅ Handles product not found gracefully
- ✅ CORS enabled for frontend access
Environment Variables
SUPABASE_URL: Auto-injected by SupabaseSUPABASE_SERVICE_ROLE_KEY: Auto-injected by Supabase
Testing
# 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
supabase functions deploy product-lookup