node-red-contrib-open-food-facts 0.2.0
A Node-RED node that provides easy integration with the Open Food Facts API. Search for products, retrieve product information, add products, and manage product images.
Node-RED Open Food Facts
A Node-RED integration for the Open Food Facts API, providing easy access to food product information, nutrition facts, and ingredient details from the world's largest open food database.
Features
- Product Lookup: Retrieve detailed product information by barcode
- Product Search: Search for products using various criteria (name, brand, category, etc.)
- Taxonomy Access: Access categorized data for additives, allergens, brands, and more
- Product Management: Add new products and upload product photos (requires authentication)
- Insights Access: Get random insights from Robotoff for product improvement
- Asynchronous Operations: All API calls are non-blocking
- Error Handling: Comprehensive error handling with custom error types
- Type Safety: Built with modern JavaScript features
Installation
Install using the Node-RED palette manager or via npm:
npm install node-red-contrib-open-food-facts
Nodes
Basic Nodes
OpenFoodFacts Get Product
Retrieve product information by barcode.
Inputs:
msg.payload
: Barcode string (if not configured in node)
Outputs:
msg.payload
: Product object with details like name, brand, ingredients, nutrition facts
OpenFoodFacts Search Products
Search for products using various filters.
Inputs:
msg.payload
: Search parameters object
Example search parameters:
{
"search_terms": "chocolate",
"brands": "Nestle",
"categories": "snacks",
"page": 1,
"pageSize": 20
}
Outputs:
msg.payload
: Search results including count, page information, and products array
OpenFoodFacts Get Taxonomy
Access categorized data (additives, allergens, brands, etc.).
Inputs:
msg.payload
: Taxonomy type (e.g., "additives", "allergens", "brands")
Outputs:
msg.payload
: Taxonomy data object
Extended Nodes
OpenFoodFacts Add Product
Add a new product to the OpenFoodFacts database (requires authentication).
Configuration:
- Username and password credentials required
Inputs:
msg.payload
: Product data object withcode
,brands
(optional),labels
(optional)
Outputs:
msg.payload
: API response
OpenFoodFacts Upload Photo
Upload a photo for a product (requires authentication).
Configuration:
- Username and password credentials required
Inputs:
msg.payload
: Object containing:barcode
: Product barcodeimage
: Image filetype
: Object withfield
(front/ingredients/nutrition) andlanguageCode
Outputs:
msg.payload
: API response
OpenFoodFacts Get Additives
Retrieve the additives taxonomy.
Outputs:
msg.payload
: Additives taxonomy data
OpenFoodFacts Get Allergens
Retrieve the allergens taxonomy.
Outputs:
msg.payload
: Allergens taxonomy data
OpenFoodFacts Get Brands
Retrieve the brands taxonomy.
Outputs:
msg.payload
: Brands taxonomy data
OpenFoodFacts Get Random Insight
Get random insights from OpenFoodFacts Robotoff.
Configuration:
count
: Number of insights to retrieve (default: 1)lang
: Language code for filtering (optional)
Outputs:
msg.payload
: Random insights from Robotoff
Example Flows
Basic Product Lookup
[
{
"id": "inject-barcode",
"type": "inject",
"payload": "3017620422003",
"payloadType": "str",
"topic": "",
"name": "Inject Barcode",
"wires": [["get-product"]]
},
{
"id": "get-product",
"type": "openfoodfacts-get-product",
"name": "",
"wires": [["debug"]]
},
{
"id": "debug",
"type": "debug",
"name": "",
"active": true,
"wires": []
}
]
Search by Category
[
{
"id": "search-inject",
"type": "inject",
"payload": "{\"categories\": \"beverages\", \"page\": 1}",
"payloadType": "json",
"topic": "",
"name": "Search Beverages",
"wires": [["search-products"]]
},
{
"id": "search-products",
"type": "openfoodfacts-search-products",
"name": "",
"wires": [["debug"]]
},
{
"id": "debug",
"type": "debug",
"name": "",
"active": true,
"wires": []
}
]
API Reference
Product Object Structure
{
"code": "3017620422003",
"product_name": "Nutella",
"brands": "Ferrero",
"categories": "Spreads, Sweet spreads, Chocolate spreads",
"ingredients_text": "Sugar, Palm oil, Hazelnuts...",
"nutriments": {
"energy_100g": 2252,
"fat_100g": 30.9,
"carbohydrates_100g": 57.5,
"proteins_100g": 6.3
},
// ... more fields
}
Search Parameters
Parameter | Type | Description |
---|---|---|
search_terms | string | General search query |
brands | string | Filter by brand |
categories | string | Filter by category |
code | string | Filter by barcode |
countries | string | Filter by country |
page | number | Page number (default: 1) |
pageSize | number | Results per page (default: 20) |
Error Handling
The nodes emit errors that can be caught using a catch node. Common errors include:
- Product not found
- Invalid barcode format
- Network connectivity issues
- API rate limiting
Testing
Run the test suite:
npm test
Contributing
Contributions are welcome! Please see our Contributing Guidelines for details.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Credits
This node uses the Open Food Facts API. Open Food Facts is a collaborative project with contributors from around the world.
Support
- For issues and feature requests, please use the GitHub issue tracker
- For questions about the Open Food Facts API, visit their documentation
Acknowledgments
- Open Food Facts team for maintaining the amazing food products database
- Node-RED community for the excellent IoT platform