API/Read: Difference between revisions

From Open Food Facts wiki
No edit summary
No edit summary
Line 1: Line 1:
[[Category:Developer]] [[Category:API]]
[[Category:Developer]] [[Category:API]]
<< Back to [[API]] (required read)
<< Back to [[API]] (required read)
'''Please send a UserAgent HTTP Header with the name of the app/service querying, the version, system and an url if you have one''', so that you are not blocked by mistake*
* e.g. UserAgent: CoolFoodApp - Android - Version 1.0 - https://coolfoodapp.com


== READ API Documentation ==
== READ API Documentation ==

Revision as of 18:09, 25 April 2019

<< Back to API (required read)

Please send a UserAgent HTTP Header with the name of the app/service querying, the version, system and an url if you have one, so that you are not blocked by mistake*

READ API Documentation

Downloading static data

It is recommended to use the live API to get fresh data about products, the minute they are uploaded to the database. However, in some cases, you may need a snapshot. They are available at:

CSV API

The character that separates fields is <tab> (tabulation).

Encoding

The file encoding is Unicode UTF-8.

MongoDB dump

Field reference

The fields used in the api. https://world.openfoodfacts.org/data/data-fields.txt

JSON interface

Pagination of results

If you're looking for all products within a facet (eg: https://fr-en.openfoodfacts.org/category/pizzas.json), you'll only have the 1st page. To move from page to page:

https://fr-en.openfoodfacts.org/category/pizzas/1.json
https://fr-en.openfoodfacts.org/category/pizzas/2.json

Countries and Language of the Response

You can either use the global (https://world.openfoodfacts.org, https://ssl-api.openfoodfacts.org) or local (https://fr.openfoodfacts.org,https://en.openfoodfacts.org…) domains for your API queries

A few things to note

Country code (cc) and Language of the interface (lc)

By default, the country code (cc) and language of the interface (lc) are set through the subdomain.

Examples
  1. https://world.openfoodfacts.org --> cc = world, lc = en (default language for the "country")
  2. https://fr.openfoodfacts.org --> cc = fr (France), lc = fr (French)
  3. https://jp.openfoodfacts.org --> cc = jp (Japan), lc = ja (Japanese)
  4. https://ch.openfoodfacts.org --> cc = ch (Switzerland), lc = de (German, set as main language for Switzerland)
  5. https://ch-fr.openfoodfacts.org --> cc = ch, lc = fr (French)

Over-riding Country code (cc) and Language of the interface (lc) using cc and lc parameters

If you pass ?cc=us and/or &lc=it, it will set the country to US and the language to Italian -> if you just pass cc, the lc will be the one set in the subdomain. e.g. world.openfoodfacts.org + cc = fr --> cc = fr, lc = en (default language of world)

The cc affects which results are returned. cc = fr -> you get only products with France listed in the countries where sold field.

The lc affects the language in which results will come back.

If the results include links to products, those links will use a new subdomain that corresponds to the overrides.


Viewing a product

API/Read/Product

Searching for products

API/Read/Search