Line 5: |
Line 5: |
| | | |
| <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>The new version of the documentation is available here: |
| + | * [https://openfoodfacts.github.io/openfoodfacts-server/reference/api/ API V2 - new OpenAPI documentation] - Work in Progress |
| + | * [https://openfoodfacts.github.io/openfoodfacts-server/reference/api-v3/ API V3 - new OpenAPI documentation] - Work in Progress |
| </big> | | </big> |
| | | |
Line 11: |
Line 15: |
| === If the edit was successful === | | === If the edit was successful === |
| | | |
− | <code> | + | <pre> |
− | {"status_verbose":"fields saved","status":1} | + | { |
− | </code> | + | ... |
| + | "status_verbose": "fields saved", |
| + | "status": 1 |
| + | ... |
| + | } |
| + | </pre> |
| | | |
| === If there was an issue === | | === If there was an issue === |
Line 24: |
Line 33: |
| | | |
| == Authentication == | | == Authentication == |
− | | + | Fields: |
− | * User_id | + | * user_id: string |
− | * Password | + | * password: string |
| | | |
| 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] ) |
Line 34: |
Line 43: |
| * 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) |
| * It is possible for adding images (as many as you like) | | * It is possible for adding images (as many as you like) |
− | * 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 === |
Line 40: |
Line 50: |
| 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 it easily. Better yet, introduce yourself on Slack :-) |
| | | |
| == Manipulating photos for a product == | | == Manipulating photos for a product == |
Line 48: |
Line 58: |
| == Posting a new product == | | == Posting a new product == |
| | | |
− | Do a GET request, otherwise you'll get <code> {“status_verbose”: “no code or invalid code”,“status”: 0}</code> | + | 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>
| + | '''Endpoint:''' <code>https://world.openfoodfacts.org/cgi/product_jqm2.pl</code>(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>
| + | '''Testing endpoint:'''<code>https://world.openfoodfacts.net/cgi/product_jqm2.pl</code> |
| | | |
| === Quick overview === | | === Quick overview === |
Line 69: |
Line 83: |
| | | |
| ==== Status after save ==== | | ==== Status after save ==== |
| + | <pre> |
| + | { |
| + | "status_verbose": "fields saved", |
| + | "status": 1 |
| + | } |
| + | </pre> |
| | | |
− | * {"Status_verbose":"fields saved","status":1}
| + | === Examples === |
− | | |
− | === Example === | |
| | | |
| <sup>(remember to do tests on world.openfoodfacts.net - login and password: off)</sup> | | <sup>(remember to do tests on world.openfoodfacts.net - login and password: off)</sup> |
Line 78: |
Line 96: |
| ==== Query 1 : Unauthentified query ==== | | ==== 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 ==== |
Line 84: |
Line 104: |
| <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 : Authenticated 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 ==== |
Line 109: |
Line 131: |
| | | |
| === Posting additional photos === | | === Posting additional photos === |
| + | '''Type:''' POST |
| + | |
| + | '''Endpoint:''' <code>/cgi/product_image_upload.pl</code> |
| + | |
| + | Fields: |
| + | * <code>code</code>: the barcode |
| + | * <code>imagefield</code>: (front | ingredients | nutrition) |
| | | |
− | * Photos post on /cgi/product_image_upload.pl
| + | Please refer to the more complete: [[API/Write/Photos]] |
− | ** Code: the barcode
| |
− | ** Imagefield: (front | ingredients | nutrition)
| |
| | | |
| ==== Add more pictures without selecting them ==== | | ==== Add more pictures without selecting them ==== |
Line 142: |
Line 169: |
| </pre> | | </pre> |
| | | |
− | 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 '''adds''' 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> |
Line 417: |
Line 444: |
| | | |
| 12% wine | | 12% wine |
− | <pre>nutriment_unit=%25%20vol&nutriment_alcohol=12</pre> | + | <pre>nutriment_alcohol_unit=%25%20vol&nutriment_alcohol=12</pre> |
| | | |
| ==== Adding the carbon footprint ==== | | ==== Adding the carbon footprint ==== |