Changes

Jump to navigation Jump to search
129 bytes removed ,  20:42, 31 May 2019
no edit summary
Line 1: Line 1: −
[[Category:Developer]] [[Category:API]]
+
[[Category:Developer]]
<Back to [[API]](Required reading)
+
[[Category:API]]
   −
== WRITE API Documentation ==
+
[[API|← Back to API]] (Required reading)
   −
<big>First of all, remember to do tests on https://world.openfoodfacts.net - login and password: off.  
+
<big>First of all, remember to do tests on https://world.openfoodfacts.net - login and password: off.
 
</big>
 
</big>
   −
=== Status Codes ===
+
== Status Codes ==
   −
==== If the edit was successful ====
+
=== If the edit was successful ===
<pre>
+
 
 +
<code>
 
{"status_verbose":"fields saved","status":1}
 
{"status_verbose":"fields saved","status":1}
</pre>
+
</code>
==== If there was an issue ====
+
 
===== Wrong password =====
+
=== If there was an issue ===
 +
 
 +
==== Wrong password ====
 +
 
 
HTML 200 code + an HTML page with a link to login
 
HTML 200 code + an HTML page with a link to login
+
 
 
Example: https://world.openfoodfacts.org/cgi/product_jqm2.pl?code=0048151623426&user_id=usernameexample&password=*****&product_name=KIRI%2
 
Example: https://world.openfoodfacts.org/cgi/product_jqm2.pl?code=0048151623426&user_id=usernameexample&password=*****&product_name=KIRI%2
    +
== Authentication ==
   −
=== Authentification ===
+
* User_id
* user_id
+
* Password
* password
      
WARNING: If the password is not correct, the API will currently "silently" fail, both for image addition and product data addition (will return HTML 200 code + an html page with a link to login - [https://world.openfoodfacts.org/cgi/product_jqm2.pl?code=0048151623426&user_id=usernameexample&password=*****&product_name=KIRI%2 example] )
 
WARNING: If the password is not correct, the API will currently "silently" fail, both for image addition and product data addition (will return HTML 200 code + an html page with a link to login - [https://world.openfoodfacts.org/cgi/product_jqm2.pl?code=0048151623426&user_id=usernameexample&password=*****&product_name=KIRI%2 example] )
   −
==== Anonymous contribution ====
+
=== Anonymous contribution ===
    
* It is possible for new products (no anonymous modification is possible though, for obvious reasons)
 
* It is possible for new products (no anonymous modification is possible though, for obvious reasons)
Line 32: Line 36:  
* If you detect an error 200 (wrong password), please retry the query without user_id and password. That way the contribution will be accepted. Otherwise, the photo will get lost :(
 
* If you detect an error 200 (wrong password), please retry the query without user_id and password. That way the contribution will be accepted. Otherwise, the photo will get lost :(
   −
==== Global account ====
+
=== Global account ===
 +
 
 
If you want to avoid coding the detection of password errors, login stuff… you can create a global account for all your users.
 
If you want to avoid coding the detection of password errors, login stuff… you can create a global account for all your users.
    
You can create a global account to let the users of your app contribute. please name it YourApp_app or something like that, so that we can spot them easily. Better yet, introduce yourself on Slack :-)
 
You can create a global account to let the users of your app contribute. please name it YourApp_app or something like that, so that we can spot them easily. Better yet, introduce yourself on Slack :-)
   −
=== Manipulating photos for a product ===
+
== Manipulating photos for a product ==
 +
 
 
[[API/Write/Photos]]
 
[[API/Write/Photos]]
    +
== Posting a new product ==
 +
 +
Do a GET request, otherwise you'll get <code> {“status_verbose”: “no code or invalid code”,“status”: 0}</code>
 +
 +
URL: <pre>https://world.openfoodfacts.org/cgi/product_jqm2.pl</pre> (Product post)<sup>(remember to do tests on world.openfoodfacts.net - login and password: off )</sup>
 +
 +
URL for your tests : <pre>https://world.openfoodfacts.net/cgi/product_jqm2.pl</pre>
 +
 +
=== Quick overview ===
 +
 +
* Var foodfact = { barcode : '0048151623426', name : 'Product name', energy: 500, energy_unit: "kJ", weight: 282 };
 +
* Var postData = {
 +
* Code : foodfact.barcode,
 +
* User_id : "mesinfosnutritionelles",
 +
* Password : "****",
 +
* Product_name : foodfact.name?foodfact.name:foodfact.shop_label,
 +
* Quantity : foodfact.weight?""+foodfact.weight+" g":undefined,
 +
* Stores : "Walmart",
 +
* Nutriment_energy :foodfact.energy,
 +
* Nutriment_energy_unit :foodfact.energy_unit,
 +
* Nutrition_data_per :"serving"
 +
 +
==== Status after save ====
 +
 +
* {"Status_verbose":"fields saved","status":1}
 +
 +
=== Example ===
   −
=== Posting a new product ===
+
<sup>(remember to do tests on world.openfoodfacts.net - login and password: off)</sup>
* Do a GET request, otherwise you'll get <pre> {“status_verbose”: “no code or invalid code”,“status”: 0}</pre>
  −
* URL: <pre>https://world.openfoodfacts.org/cgi/product_jqm2.pl</pre> (Product post)<sup>(remember to do tests on world.openfoodfacts.net - login and password: off )</sup>
  −
* URL for your tests : <pre>https://world.openfoodfacts.net/cgi/product_jqm2.pl</pre>
  −
==== Quick overview ====
  −
* var foodfact = { barcode : '0048151623426', name : 'Product name', energy: 500, energy_unit: "kJ", weight: 282 };
  −
* var postData = {
  −
* code        : foodfact.barcode,
  −
* user_id      : "mesinfosnutritionelles",
  −
* password    : "****",
  −
* product_name : foodfact.name?foodfact.name:foodfact.shop_label,
  −
* quantity    : foodfact.weight?""+foodfact.weight+" g":undefined,
  −
* stores      : "Walmart",
  −
* nutriment_energy      :foodfact.energy,
  −
* nutriment_energy_unit :foodfact.energy_unit,
  −
* nutrition_data_per    :"serving"
     −
=====Status after save =====
+
==== Query 1 : Unauthentified query ====
* {"status_verbose":"fields saved","status":1}
     −
==== Example ====
  −
<sup>(remember to do tests on world.openfoodfacts.net - login and password: off)</sup><br>
  −
===== Query 1 : Unauthentified query =====
   
<pre>https://world.openfoodfacts.net/cgi/product_jqm2.pl?code=0048151623426&product_name=Maryland%20Choc%20Chip&quantity=230g&brands=Golden%20Cookies&nutriment_energy=450&nutriment_energy_unit=kJ&nutrition_data_per=serving&ingredients_text=Fortified%20wheat%20flour%2C%20Chocolate%20chips%20%2825%25%29%2C%20Sugar%2C%20Palm%20oil%2C%20Golden%20syrup%2C%20Whey%20and%20whey%20derivatives%20%28Milk%29%2C%20Raising%20agents%2C%20Salt%2C%20Flavouring&traces=Milk%2C+Soya%2C+Nuts%2C+Wheat</pre>
 
<pre>https://world.openfoodfacts.net/cgi/product_jqm2.pl?code=0048151623426&product_name=Maryland%20Choc%20Chip&quantity=230g&brands=Golden%20Cookies&nutriment_energy=450&nutriment_energy_unit=kJ&nutrition_data_per=serving&ingredients_text=Fortified%20wheat%20flour%2C%20Chocolate%20chips%20%2825%25%29%2C%20Sugar%2C%20Palm%20oil%2C%20Golden%20syrup%2C%20Whey%20and%20whey%20derivatives%20%28Milk%29%2C%20Raising%20agents%2C%20Salt%2C%20Flavouring&traces=Milk%2C+Soya%2C+Nuts%2C+Wheat</pre>
   −
===== Result 2 =====
+
==== Result 2 ====
 +
 
 
<pre>https://uk.openfoodfacts.net/product/0072417136160/maryland-choc-chip</pre>
 
<pre>https://uk.openfoodfacts.net/product/0072417136160/maryland-choc-chip</pre>
   −
===== Query 2 : Authentified query =====
+
==== Query 2 : Authentified query ====
 +
 
 
<pre>https://world.openfoodfacts.org/cgi/product_jqm2.pl?code=0048151623426&user_id=usernameexample&password=*****&product_name=KIRI%20GOUTER%20280G%208%20PORTIONS&quantity=282%20g&stores=Intermarch%C3%A9&nutriment_energy=500&nutriment_energy_unit=kJ&nutrition_data_per=serving</pre>
 
<pre>https://world.openfoodfacts.org/cgi/product_jqm2.pl?code=0048151623426&user_id=usernameexample&password=*****&product_name=KIRI%20GOUTER%20280G%208%20PORTIONS&quantity=282%20g&stores=Intermarch%C3%A9&nutriment_energy=500&nutriment_energy_unit=kJ&nutrition_data_per=serving</pre>
   −
===== Result 2 =====
+
==== Result 2 ====
====== If credentials are correct ======
+
 
 +
===== If credentials are correct =====
 +
 
 
<pre>Standard success status, see above</pre>
 
<pre>Standard success status, see above</pre>
====== If credentials are not correct ======
+
 
 +
===== If credentials are not correct =====
 +
 
 
Will give you a responsive HTML login page.
 
Will give you a responsive HTML login page.
   −
==== See editing a product for details on fields ====
+
=== See editing a product for details on fields ===
==== Posting several values for a field ====
+
 
 +
=== Posting several values for a field ===
 +
 
 
When adding values, send to the field labels as comma separated values that are canonicalised and added to the _tags array
 
When adding values, send to the field labels as comma separated values that are canonicalised and added to the _tags array
 
<pre>labels = "labelA, labelB"</pre>
 
<pre>labels = "labelA, labelB"</pre>
 
Reading back, use labels_tags to get an array of labels
 
Reading back, use labels_tags to get an array of labels
   −
=== Editing an existing product ===
+
== Editing an existing product ==
 +
 
 +
=== Posting additional photos ===
   −
==== Posting additional photos ====
   
* Photos post on /cgi/product_image_upload.pl
 
* Photos post on /cgi/product_image_upload.pl
** code: the barcode
+
** Code: the barcode
** imagefield: (front | ingredients | nutrition)
+
** Imagefield: (front | ingredients | nutrition)
===== Add more pictures without selecting them =====
+
 
* imagefield: (other)
+
==== Add more pictures without selecting them ====
 +
 
 +
* Imagefield: (other)
 +
 
 +
==== Select the Front picture ====
 +
 
 +
* Imgupload_front : your image file if imagefield:front
 +
 
 +
==== Select the Ingredients picture ====
 +
 
 +
* Imgupload_ingredients: your image file if imagefield:ingredients
   −
===== Select the Front picture =====
+
==== Select the Nutrition Facts picture ====
* imgupload_front : your image file if imagefield:front
  −
===== Select the Ingredients picture =====
  −
* imgupload_ingredients: your image file if imagefield:ingredients
  −
===== Select the Nutrition Facts picture =====
  −
* imgupload_nutrition: your image file if imagefield:nutrition
      +
* Imgupload_nutrition: your image file if imagefield:nutrition
    +
=== Editing the product ===
   −
==== Editing the product ====
+
==== Adding values to a field that is already filled ====
   −
===== Adding values to a field that is already filled =====
   
You just have to prefix <code>add_</code> before the name of the field. Examples:
 
You just have to prefix <code>add_</code> before the name of the field. Examples:
 
<pre>
 
<pre>
Line 114: Line 143:     
This '''add''' a new value but '''doesn't delete the previous ones'''. Adding values doesn't need authentication but take it into account. Examples:
 
This '''add''' a new value but '''doesn't delete the previous ones'''. Adding values doesn't need authentication but take it into account. Examples:
 +
 
* <code><nowiki>https://world.openfoodfacts.net/cgi/product_jqm2.pl?code=0048151621226&add_brands=Brand%202</nowiki></code>
 
* <code><nowiki>https://world.openfoodfacts.net/cgi/product_jqm2.pl?code=0048151621226&add_brands=Brand%202</nowiki></code>
 
* <code><nowiki>https://world.openfoodfacts.net/cgi/product_jqm2.pl?code=0048151621226&user_id=username&password=*****&add_brands=Brand%203</nowiki></code>
 
* <code><nowiki>https://world.openfoodfacts.net/cgi/product_jqm2.pl?code=0048151621226&user_id=username&password=*****&add_brands=Brand%203</nowiki></code>
    +
=== Give the barcode ===
   −
==== Give the barcode ====
   
<pre>code=072417136160</pre>
 
<pre>code=072417136160</pre>
    +
=== Add the brand ===
   −
==== Add the brand ====
   
<pre>brands=Heinz</pre>
 
<pre>brands=Heinz</pre>
   −
==== Add the name ====
+
=== Add the name ===
 +
 
 
<pre>product_name=Maryland%20Choc%20Chip</pre>
 
<pre>product_name=Maryland%20Choc%20Chip</pre>
==== Add the quantity ====
+
 
 +
=== Add the quantity ===
 +
 
 
<pre>quantity=230g</pre>
 
<pre>quantity=230g</pre>
==== Add the packager code ====
+
 
 +
=== Add the packager code ===
 +
 
 
<pre>emb_codes=EMB%2013330</pre>
 
<pre>emb_codes=EMB%2013330</pre>
   −
==== Add the packaging type ====
+
=== Add the packaging type ===
 +
 
 
<pre>packaging=Cardboard</pre>
 
<pre>packaging=Cardboard</pre>
   −
==== Add the labels ====
+
=== Add the labels ===
 +
 
 
<pre>labels=Vegan%2C%20Fat%20free</pre>
 
<pre>labels=Vegan%2C%20Fat%20free</pre>
   −
==== Add the Stores where bought ====
+
=== Add the Stores where bought ===
 +
 
 
<pre>stores=Intermarch%C3%A9</pre>
 
<pre>stores=Intermarch%C3%A9</pre>
==== Add the category ====
+
 
 +
=== Add the category ===
 +
 
 
<pre>categories=Cookies</pre>
 
<pre>categories=Cookies</pre>
==== Add the best before date ====
+
 
 +
=== Add the best before date ===
 +
 
 
<pre>expiration_date=</pre>
 
<pre>expiration_date=</pre>
   −
==== Add the link to the official webpage of the product ====
+
=== Add the link to the official webpage of the product ===
 +
 
 
<pre>link=</pre>
 
<pre>link=</pre>
   −
==== Add the ingredients ====
+
=== Add the ingredients ===
 +
 
 
<pre>ingredients_text=Fortified%20wheat%20flour%2C%20Chocolate%20chips%20%2825%25%29%2C%20Sugar%2C%20Palm%20oil%2C%20Golden%20syrup%2C%20Whey%20and%20whey%20derivatives%20%28Milk%29%2C%20Raising%20agents%2C%20Salt%2C%20Flavouring</pre>
 
<pre>ingredients_text=Fortified%20wheat%20flour%2C%20Chocolate%20chips%20%2825%25%29%2C%20Sugar%2C%20Palm%20oil%2C%20Golden%20syrup%2C%20Whey%20and%20whey%20derivatives%20%28Milk%29%2C%20Raising%20agents%2C%20Salt%2C%20Flavouring</pre>
==== Add ingredient traces ====
+
 
 +
=== Add ingredient traces ===
 +
 
 
<pre>traces=Milk%2C+Soya%2C+Nuts%2C+Wheat</pre>
 
<pre>traces=Milk%2C+Soya%2C+Nuts%2C+Wheat</pre>
   −
==== Add the main language ====
+
=== Add the main language ===
You can set the main language of the product.<br>
+
 
<pre>lang=fr</pre><br><br>
+
You can set the main language of the product.
 +
 
 +
<pre>lang=fr</pre>
 +
 
 
(NOT LIVE YET)
 
(NOT LIVE YET)
 
In the case of a multilingual product, you can specify the main language of the product, and you can then specify values and images for different languages by suffixing the language code to the other fields.
 
In the case of a multilingual product, you can specify the main language of the product, and you can then specify values and images for different languages by suffixing the language code to the other fields.
   −
==== Add the nutrition facts ====
+
=== Add the nutrition facts ===
===== Indicate the absence of nutrition facts =====
+
 
 +
==== Indicate the absence of nutrition facts ====
 +
 
 
<pre>no_nutrition_data=on (indicates if the nutrition facts are not indicated on the food label)</pre>
 
<pre>no_nutrition_data=on (indicates if the nutrition facts are not indicated on the food label)</pre>
   −
===== Add nutrition facts values, units and base =====
+
==== Add nutrition facts values, units and base ====
====== Define the basis for the values ======
+
 
 +
===== Define the basis for the values =====
 +
 
 
<pre>nutrition_data_per=100g</pre>
 
<pre>nutrition_data_per=100g</pre>
<br>'''OR'''<br>
+
 
 +
'''OR'''
 +
 
 
<pre>nutrition_data_per=serving</pre>
 
<pre>nutrition_data_per=serving</pre>
 
<pre>serving_size=38g</pre>
 
<pre>serving_size=38g</pre>
   −
====== Input values and units ======
+
===== Input values and units =====
 +
 
 
<pre>nutriment_energy=450</pre>
 
<pre>nutriment_energy=450</pre>
 
<pre>nutriment_energy_unit=kJ</pre>
 
<pre>nutriment_energy_unit=kJ</pre>
   −
====== Values ======
+
===== Values =====
 +
 
 
<pre>
 
<pre>
 
nutriment_energy
 
nutriment_energy
Line 265: Line 322:  
</pre>
 
</pre>
   −
====== Units ======
+
===== Units =====
 +
 
 
<pre>
 
<pre>
 
nutriment_energy_unit
 
nutriment_energy_unit
Line 356: Line 414:  
</pre>
 
</pre>
   −
===== Adding the alcohol % of wine =====
+
==== Adding the alcohol % of wine ====
 +
 
 
12% wine
 
12% wine
 
<pre>nutriment_unit=%25%20vol&nutriment_alcohol=12</pre>
 
<pre>nutriment_unit=%25%20vol&nutriment_alcohol=12</pre>
   −
===== Adding the carbon footprint =====
+
==== Adding the carbon footprint ====
 +
 
 
<pre>nutriment_carbon-footprint</pre>
 
<pre>nutriment_carbon-footprint</pre>
 
<pre>nutriment_carbon-footprint_unit</pre>
 
<pre>nutriment_carbon-footprint_unit</pre>
   −
=== Adding a comment to your edit ===
+
== Adding a comment to your edit ==
 +
 
 
<pre>comment=Automated%20Edit</pre>
 
<pre>comment=Automated%20Edit</pre>
72

edits

Navigation menu