# Media

The article highlights the API endpoints and simple methods used to add photos and videos for products on Omnitron.

On the Omnitron panels, there are Product Pictures and Product Videos sections on the detail pages of the existing or pending products in **Products and Catalogs > Product Pool** and **Integration > Pending Products**.

<figure><img src="/files/4fJ9wTU17chIi12ft1h2" alt=""><figcaption></figcaption></figure>

Frontend images and videos are sent to Omnitron via API.

{% hint style="warning" %}
The accepted file formats for the images are `.png`, `.jpg`, and `.jpeg`.

To customize image dimensions, the following dynamic setting is used:

* **MAX\_IMAGE\_DIMENSIONS**

  This setting is employed to set the maximum dimensions of product images. Its purpose is to ensure that product images do not exceed specific width and height values, typically configured to maintain image quality, optimize page loads, and enhance overall performance.

  Default values are as follows:

  ```
  MAX_IMAGE_DIMENSIONS = {'WIDTH': 2000, 'HEIGHT': 2000}
  ```

  **Path:** `/api/v1/dynamic_settings/`

  **Method:** `POST`

  **Body:**

  ```json
  {
    "key": "MAX_IMAGE_DIMENSIONS",
    "value": {"WIDTH": 3000, "HEIGHT": 3000}
  }
  ```

{% endhint %}

## HTTP Methods

### `GET` Product Images

This method is used to get images of products.

Path: `/api/v1/product_image/?limit=100&product={product_pk}`

**Response**

```json
    {
  "count": 3,
  "next": null,
  "previous": null,
  "results": [
    {
      "pk": 491,
      "product": 16201, #product pk
      "image": "https://{customer_omnitron_url}/products/2017/03/24/16201/7ab3a475-d208-4650-bb14-053acf955daa.jpg",
      "order": 0,
      "source":  "integration",
      "modified_date": "2022-11-25T12:06:42.954200Z",
      "created_date": "2022-11-25T12:06:42.954186Z"

    },
    {
      "pk": 493,
      "product": 16201, #product pk
      "image": "https://{customer_omnitron_url}/products/2017/03/24/16201/2906fa81-8c3e-41fa-9884-904ca431cd5e.jpg",
      "order": 1,
      "source":  "integration",
      "modified_date": "2022-11-25T12:06:42.954200Z",
      "created_date": "2022-11-25T12:06:42.954186Z"
    },
    {
      "pk": 494,
      "product": 16201, #product pk
      "image": "https://{customer_omnitron_url}/products/2017/03/24/16201/f8dc7c1e-3f5d-4cc2-965c-4aa72bf15e1f.jpg",
      "order": 2,
      "source":  "integration",
      "modified_date": "2022-11-25T12:06:42.954200Z",
      "created_date": "2022-11-25T12:06:42.954186Z"
    }
  ]
}
```

### `GET` Product Videos

This method is used to get videos of products.

Path: `/api/v1/product_video/?limit=100&product={product_pk}`

**Response**

```json
    {
  "count": 2,
  "next": null,
  "previous": null,
  "results": [
    {
      "pk": 168,
      "product": 52,
      "video": "https://{customer_omnitron_url}/product_videos/2020/06/05/814a770c-96f4-4f1e-85e4-f100ffcabc96.mp4",
      "order": 0,
      "modified_date": "2022-07-05T05:36:03.865894Z",
      "created_date": "2022-07-05T05:36:03.865865Z"
    },
    {
      "pk": 169,
      "product": 52,
      "video": "https://{customer_omnitron_url}/product_videos/2020/06/05/f77661e0-023b-4688-a43e-02c8d37ec836.mp4",
      "order": 1,
      "modified_date": "2022-07-05T05:36:03.865894Z",
      "created_date": "2022-07-05T05:36:03.865865Z"
    }
  ]
}

```

### `POST` Create Product Image

This method is used to upload images of products.

Path: `/api/v1/product_image/`

<table data-header-hidden><thead><tr><th width="218.8046875"></th><th></th></tr></thead><tbody><tr><td><strong>Parameter</strong></td><td><strong>Detail</strong></td></tr><tr><td>product</td><td>PK information of the product with media</td></tr><tr><td>image</td><td>Image with .png or .jpeg extension</td></tr><tr><td>video</td><td>Video with .mp4 extension</td></tr><tr><td>source</td><td>Indicates what source the image came from<br>Enum field (integration or unified values)</td></tr></tbody></table>

```json
{
    "image": {File},
    "product": {product_pk},
    "source": "integration" 
}

```

**Response**

```json
{
     "pk":20026,
     "product":1,
     "image":"http://{customer_omnitron_url}/media/products/2021/05/25/1/5e0b2bc0-bee2-4ff0-a7db-9ee622510094.jpg",
     "Order":0,
     "source":  "integration",
     "modified_date": "2022-11-25T12:06:42.954200Z",
     "created_date": "2022-11-25T12:06:42.954186Z"
}
```

### `POST` Create Product Video

This method is used to upload videos of products.

Path: `/api/v1/product_video/`

```json
   {
video: {File},
"product": {product_pk}
}
```

**Response**

```json
{
    "pk":1,
    "product":1,
    "video":"http://{customer_omnitron_url}/media/product_videos/2021/05/25/6befb990-b167-4fed-9a77-b8267503cb88.mp4",
    "order":0,
    "modified_date": "2022-07-05T05:36:03.865894Z",
    "created_date": "2022-07-05T05:36:03.865865Z"
}
```

**Response / 400**

The following errors may occur if the payload of the POST request is not correct while creating an image on a product.

```json
 {
    "product": [
        "Incorrect type. Expected pk value, received unicode."
    ]
}
-- OR 
{
    "image": [
        "Upload a valid image. The file you uploaded was either not an image or a corrupted image."
    ]
}
-- OR
{
    "image": [
        "No file was submitted."
    ]
}
```

### `PATCH` Update Product Image

This method is used to change the order of the images uploaded for the product.

Path: `/api/v1/product_image/{pk}/`

```json
{   
    "pk": 20029, 
    "order": 1
}
```

**Response**

```json
{   
    "pk":20029,
    "product":1,
    "image":"http://{customer_omnitron_url}/media/products/2021/06/01/1/689df4bf-d549-45e2-aae8-f958ea357b7e.jpg",
    "order":1
}
```

### `PATCH` Update Product Video

This method is used to change the order of the videos uploaded for the product.

Path: `/api/v1/product_video/{pk}/`

```json
{   
    "pk": 20129, 
    "order": 1
}
```

**Response / 200**

If the PATCH response is successful, it returns the following response.

```json
{   
    "pk":20129,
    "product":1,
    "video":"http://{customer_omnitron_url}/media/products/2021/06/01/1/689df4bf-d549-45e2-aae8-f958ea357b7e.mp4",
    "Order":1,
    "source": null,
    "modified_date": "2023-01-03T18:42:18.358380Z",
    "created_date": "2022-11-25T12:06:42.954186Z"
}
```

**Response / 400**

Following errors may take place while updating an image on a product, if the payload of the PATCH request is not correct.

```json
 {
    "order": [
        "Ensure this value is greater than or equal to 0."#if order negative
    ]
}
```

### `DELETE` Product Image

This method is used to delete the images uploaded for the product.

Path: `/api/v1/product_image/{pk}/`

**Response**

Returns HTTP204 if the DELETE request is successful. Related product image has been deleted.

### `DELETE` Product Video

This method is used to delete the videos uploaded for the product.

Path: `/api/v1/product_video/{pk}/`

**Response**

Returns HTTP204 if the DELETE request is successful. Related product video has been deleted.

### `POST` Set the Main Image of a Product

This method is used to select the main image of the product.

Path: `/api/v1/product_image/{pk}/make_special/`

```json
{
    "_pk": 20028, 
    "special_image_type": "base", 
    "_detailed": "make_special"
}

```

**Response**

```json
{
"special_image_type":"base"
}

```

## Downloadable Image

This is the structure where the images in the ERP systems of the companies are downloaded and saved to the CDN and default storage with projects and media.

### `POST` Receive Images from ERP

These methods allow the download of product images from the ERP system.

Path: `/api/v1/downloadable_image/{product_pk}/download/`

```json
{
    "url": # ERP file url
    "image_type": #(default, swatch, picto)
    "product": "<product_pk>"
    "order": <int>,
    "source": "integration",
    "modified_date": "2017-01-23T08:33:56.794003Z",
    "created_date": "2017-01-22T23:56:28.881838Z"
}
```

**Response**

HTTP200


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://apidocs.akinon.com/omnitron/pim/media.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
