New tags data model and API features

Product tags likes categories, labels, allergens, origins and many more are one of the most widely used features of Open Food Facts. They make it easy to search, group and explore products, and they are also needed to compute scores such as the Nutri-Score and Green-Score. Last week we deployed a new data model for tags and new API features to make it easier to add, update and manage product tags.

Automatically added parent tags are now stored separately from input tags

Thanks to the tags taxonomies, we can automatically add parents tags, which greatly helps searching and exploring products. For instance adding the category “Salted butters” will automatically add “Dairies”, “Fats”, “Spreads”, “Spreadable fats”, “Animal fats”, “Dairy spreads”, “Milkfat”, and “Butters”.

But previously, parent tags were directly added to the product tags, and it was impossible to see what tags were the original input tags. It made the product edit form very cluttered, and it was painful to change tags (e.g. if the product categorized as butter was in fact vegetal margarine).

We now record separately the input tags, and we are converting existing products to remove parents from input tags

Input tags from different sources (e.g. packaging, manufacturer, ingredients) are now stored separately

Similarly, it was not possible before to see which tags were added by users on the OFF website or app, or 3rd party apps, by manufacturers, or auto-added from other sources (such as allergens detected in the ingredients list). We now store input tags separately by source.

New API version v3.6

The changes are transparent for previous versions of the API so that apps can continue to read and write tags as they used to before. In particular, fields like “categories”, “categories_tags” and “categories_hierarchies” can still be accessed through older API versions.

In the new API v3.6, fields like categories_tags contain all the tags (children and parents) from all sources, and there is a new tags_sources field that gives the detail of all input tags by sources.

e.g. https://world.openfoodfacts.org/api/v3.6/product/3017620420702?fields=categories_tags,labels_tags,tags_sources

New APIs to normalize and display tags, and to get tags suggestions from taxonomies

We also recently added new APIs to manipulate tags:

Thank you!

The new tags schema and APIs is the last part of the Pomme d’API which also included new OpenAPI documentation, new schema and APIs for product photos upload and selection, and new nutrition data schema and APIs.

The project would not have been possible without the many people who provided ideas on which APIs to add or improve, who participated in all the design sessions to brainstorm and refine the new schemas and APIs, and who reviewed and tested the code changes.

We would also like to thank NLnet who funded the Pomme d’API project through the NGI0 Commons Fund. It is always very difficult to find funding for the core of our digital commons (in particular for things like infrastructure and APIs that may not be very exciting to the outside world but are crucial to the project). So we are very happy that funds like the NGI0 Commons Fund exist! :slight_smile:

This project was funded through the NGI0 Commons Fund, a fund established by NLnet with financial support from the European Commission’s Next Generation Internet programme, under the aegis of DG Communications Networks, Content and Technology under grant agreement No 101135429. Additional funding is made available by the Swiss State Secretariat for Education, Research and Innovation (SERI).