Create or Update Product
Changed onThis API allows to create or update a product (if the product already exists, its data is updated, otherwise it is created), or to analyze a test product (in which case no product is created or updated). To analyze a product, the "code" path component needs to contain the value "test" instead of a barcode.
New API to send structured product data in a JSON format instead of in a flattened list of key / value pairs field as-in the current product add / edit API that relies on a multipart/form-data format.
Important: this new Product WRITE API has been deployed in production, but it is still under development, and it may change.
This new API is used in particular to send structured packaging data: https://openfoodfacts.github.io/openfoodfacts-server/dev/explain-packaging-data/
The new API is gradually being extended to support other product fields.
Currently supported fields are:
- language specific fields (e.g. product name, ingredients text)
- tags fields (e.g. categories, labels)
- packaging fields (e.g. packagings, packagings_add, packagings_complete)
- image selection of uploaded images (e.g. front, ingredients, nutrition, packaging) for specific languages
Request
- Base URLhttps://world.openfoodfacts.org
- AuthAPI key in cookie session and API key in header User-Agent
Path parameters
The barcode of the product to create or update, or "test" to analyze the product data sent without creating or updating a product.
Request body
Example request
{
"fields": "product_name,packagings",
"tags_lc": "fr"
}Response
The response will include a "product" structure. The fields returned in this structure will depend on the value of the "fields" input field:
-
"updated" (default): all fields updated by the query will be returned, including fields that are directly generated from the updated fields. For instance, sending "packagings" or "packagings_add" will return the "packagings" field.
-
"none": no fields are returned.
-
"all": returns all fields except generated fields that need to be explicitly requested such as "knowledge_panels".
The "fields" values can also be concatenated: "all,knowledge_panels"
Example response
{
"status": "success_with_errors",
"result": {
"id": "product_updated",
"name": "Product updated",
"lc_name": "Produit mis à jour"
},
"errors": [
{
"message": {
"id": "sugars_higher_than_carbohydrates",
"name": "Sugars higher than carbohydrates",
"lc_name": "Sucres plus élevés que les glucides",
"description": "Sugars (40g) are higher than carbohydrates (35g).",
"lc_description": "Les sucres (40g) sont plus élévés que les glucdes."
},
"field": {
"id": "nutriment.sugars",
"value": "40"
},
"impact": {
"id": "nutrients_not_updated",
"name": "Nutrients not updated",
"lc_name": "Nutriments non mis à jour",
"description": "The nutrients were not updated.",
"lc_description": "Les nutriments n'ont pas été mis à jour."
}
}
]
}Changes
- breaking
added to the request body
allOflist - breaking
added
subschema #3to theallOf[subschema #3]/productrequest propertyallOflist - breaking
the
allOf[subschema #3]/productrequest property type changed from no type toobject
5 more changes in this revision
- breaking