API: Difference between revisions

From Open Food Facts wiki
No edit summary
Β 
(62 intermediate revisions by 12 users not shown)
Line 1: Line 1:
__NOINDEX__
[[Category:Developer]] [[Category:API]]
[[Category:Developer]] [[Category:API]]
The API (Application Programming Interface) is the way an application can enter in dialogue with Open Food Facts application server.


== Introduction ==
All information about the API can be found [https://openfoodfacts.github.io/openfoodfacts-server/api/ in the documentation].
=== Current status of the API ===
* Currently the API is used internally for the official Open Food Facts mobile applications (iOS, Android, Windows, and we need help !) and by dozens of reuses on various topics (Nutrition, sport…) and platforms (iOS, Android…), but does not yet follow good practices in API design.
* It is also used by several applications and while not yet stable, doesn't change much.
* You can have a look at the source code of the app
** https://github.com/openfoodfacts/cordova-app/blob/master/www/off.js
** https://github.com/openfoodfacts/cordova-app/blob/master/www/index.html
* '''Anyone with Swagger (or equivalent knowledge) willing to help us document the API is most welcome :-)'''
Β 
=== Getting help with the API ===
You can ask for help on using the API in this [https://openfoodfacts.slack.com/messages/api/ API channel on Slack]. Join us to discuss your use case and get help/code from other devs.
Β 
=== How to test the API ===
==== READ operations ====
===== Technical details =====
* You can do READ operations using production
* You should now use the SSL version of the API. The unsecure version '''WILL''' be deprecated :-)
<pre>https://ssl-api.openfoodfacts.org</pre>
===== Licence =====
Open Food Facts is under the OdBL licence (database) and CC-BY-SA (pictures). That has a couple of legal implications. Please join us on the Slack channel to discuss them.
Β 
==== WRITE operations ====
Β 
===== Use cases =====
* You can add photos and informations to Open Food Facts using the API.
** Letting your users add new products by uploading photos is the most common use case.
** Several apps already enable more advanced editing. Gamification would be welcome.
* The official mobile apps can use some help.
Β 
===== A few things =====
* Do join the API channel if you intend on using WRITE
* Do not send copyrighted photos or information using the API. Everything you send is OdBL for the data, and CC-BY-SA for the pictures. If those are not yours (eg from scraping), you bear all the legal consequences.
* You can create a global account for your app if you don't want to implement Open Food Facts user creation in your app right now. Please report it in #api so that it can be monitored for errors.
* You should do all your test edits on https://world.openfoodfacts.net (ask for the password on Slack)
Β 
=== Conventions for the API ===
* fields that end with _t are dates in the UNIX timestamp format (number of seconds since Jan 1st 1970)
* fields that end with _datetime are dates in the iso8601 format: yyyy-mm-ddThh:mn:ssZ
* fields that end with _tags are comma separated list of tags (e.g. categories_tags is the set of normalized tags computer from the categories field)
* fields that end with a language 2 letter code (e.g. fr for French) is the set of tags in that language
* fields that end with _100g correspond to the amount of a nutriment (in g) for 100 g or 100 ml of product
=== Language Bindings===
* [[API/Android|Android bindings]]
* [[API/C sharp|C# bindings]]
*Β  [[API/Go|Go bindings]] - https://github.com/openfoodfacts/openfoodfacts-go
* [[API/Java|Java bindings]]
* [[API/Javascript|JS bindings]]
* [[API/Javascript/NodeJS|NodeJS bindings]]
* [[API/Perl|Perl bindings]]
* [[API/PHP|PHP bindings]] - https://github.com/openfoodfacts/openfoodfacts-php
* [[API/Python|Python bindings]] - https://github.com/openfoodfacts/openfoodfacts-python (LIVE API) - https://github.com/openfoodfacts/OpenFoodFacts-APIRestPython (Local Dump)
* [[API/R|R bindings]]
* [[API/Ruby|Ruby bindings]] - https://github.com/openfoodfacts/openfoodfacts-ruby - gem install openfoodfacts - https://github.com/openfoodfacts/openbeautyfacts-ruby - gem install openbeautyfacts
* [[API/Scala|Scala bindings]]
* [[API/Swift|Swift bindings]]
* Please help us bring Open Food Facts to your favorite language by contributing bindings
Β 
=== SDKs ===
We have projects to create SDKs for major platforms. If you'd like to help out, please join the dedicated Slack channels.
Β 
=== Roadmap ===
[[API/Roadmap]]
=== Bugs ===
==== Reporting bugs ====
* Do not hesitate to file a bug if you find an issue in the API, or need an improvement.
==== Known bugs ====
* General bugs: https://github.com/openfoodfacts/openfoodfacts-server/issues
* API bugs: https://github.com/openfoodfacts/openfoodfacts-server/labels/api
* API milestone: https://github.com/openfoodfacts/openfoodfacts-server/milestone/8
Β 
=== Warning ===
* Some products are incomplete.
* '''You should ensure your UX tells the final user that the product is not complete, encourage them to exercise caution and/or help complete the product.'''
* When doing averages, computations… filter incomplete products to avoid issues
* Assume the data is not reliable until the product is marked as complete.
* '''In general, ensure the user exercises maintains caution (for allergens…) and be upfront about possible risks.'''
Β 
== Read API ==
Please look at [[API/Read]]
Β 
== Write API ==
Β 
Please look at [[API/Write]]
Β 
== Sister projects ==
=== Open Pet Food Facts ===
Open Pet Food Facts behaves just like Open Food Facts. Behaviours may change over time, as we tweak it.
* https://ssl-api.openpetfoodfacts.org/api/v0/product/20106836.json
Β 
=== Open Beauty Facts ===
Β 
[[API/OpenBeautyFacts]]
Β 
=== Open Products Facts ===
Β 
Open Products Facts behaves mostly like Open Food Facts. Behaviours may change over time, as we tweak it.

Latest revision as of 14:04, 5 September 2023

The API (Application Programming Interface) is the way an application can enter in dialogue with Open Food Facts application server.

All information about the API can be found in the documentation.