Images

Upload Product Image

Changed on

This endpoint allows to upload an image for a product. The image is uploaded in the request body as a base64 encoded string. Optionally, it is possible to select the uploaded image for specific information (e.g. front, ingredients, nutrition, packaging) for specific languages. Each selected image is a cropped version of the uploaded image.

If the product does not exist, it will be created.

post/api/v3/product/{code}/images

Request

  • Base URL
    https://world.openfoodfacts.org
  • Auth
    API key in cookie session and API key in header User-Agent

Path parameters

codestring required
Example:3017620422003

The barcode of the product corresponding to the image.

Request body

lcstring

2 letter code of the language of the interface. Used for localizing some fields in returned values (e.g. knowledge panels). If not passed, the language may be inferred by the country of the user (passed through the cc field or inferred by the IP address). Full list at https://static.openfoodfacts.org/data/taxonomies/languages.json

ccstring

2 letter code of the country of the user. Used for localizing some fields in returned values (e.g. knowledge panels). If not passed, the country may be inferred by the IP address of the request. Full list at https://static.openfoodfacts.org/data/taxonomies/countries.json

user_idstring

Username for login

Note: you must always use the username (and not the email) as it is far less brittle.

passwordstring password

Password for login

image_data_base64string

Base64 encoded image data (supported formats: JPEG, PNG, GIF, HEIC)

Example request

{
  "lc": "fr",
  "cc": "fr"
}

Response

The response will include a "product" structure. The fields returned in this structure will depend on the value of the "fields" input field:

  • "updated" (default): all fields updated by the query will be returned, including fields that are directly generated from the updated fields. For instance, sending "packagings" or "packagings_add" will return the "packagings" field.

  • "none": no fields are returned.

  • "all": returns all fields except generated fields that need to be explicitly requested such as "knowledge_panels".

The "fields" values can also be concatenated: "all,knowledge_panels"

status'success' | 'success_with_warnings' | 'success_with_errors' | 'failure'

Overall status of the request: whether it failed or succeeded, with or without warnings or errors.

Example response

{
  "status": "success_with_errors",
  "result": {
    "id": "product_updated",
    "name": "Product updated",
    "lc_name": "Produit mis à jour"
  },
  "errors": [
    {
      "message": {
        "id": "sugars_higher_than_carbohydrates",
        "name": "Sugars higher than carbohydrates",
        "lc_name": "Sucres plus élevés que les glucides",
        "description": "Sugars (40g) are higher than carbohydrates (35g).",
        "lc_description": "Les sucres (40g) sont plus élévés que les glucdes."
      },
      "field": {
        "id": "nutriment.sugars",
        "value": "40"
      },
      "impact": {
        "id": "nutrients_not_updated",
        "name": "Nutrients not updated",
        "lc_name": "Nutriments non mis à jour",
        "description": "The nutrients were not updated.",
        "lc_description": "Les nutriments n'ont pas été mis à jour."
      }
    }
  ]
}

Changes

    • breaking

      added to the request body allOf list

    • breaking

      the allOf[subschema #2]/selected request property type changed from no type to object

    • breaking

      the allOf[subschema #2]/product/images/uploaded/patternProperties[(?<imgid>\d+)] response's property type changed from no type to object for status

    9 more changes in this revision