Skip to main content

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 1: Product Pictures and Product Videos

Frontend images and videos are sent to Omnitron via API.

NOTE

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:

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

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

    {
"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

    {
"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/

ParameterDetail
productPK information of the product with media
imageImage with .png or .jpeg extension
videoVideo with .mp4 extension
sourceIndicates what source the image came from Enum field (integration or unified values)
{
"image": {File},
"product": {product_pk},
"source": "integration"
}

Response

     {
"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/

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

Response

   {
"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.

 {
"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}/

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


Response

 {   
"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}/

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

Response / 200

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

 {   
"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.

 {
"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/

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

Response

{
"special_image_type":"base"
}

Model

Derived from ProductImage > IntegrationRelation and StarterModel classes, image, height, width, product, order, status, hash.

Derived from ProductVideo > BaseProductVideo and IntegrationRelation classes, video, product, order, status.

ViewSet

ProductImageViewSet

These are the functions for create, update and delete requests from API. make_special is the function of the incoming request from the /api/v1/product_image/{pk}/make_special/ endpoint and this url is the endpoint that allows images to be main images.

Figure 2: ProductImageViewSet

ProductVideoViewSet

These are the functions for create, update and delete requests from API.

Figure 3: ProductVideoViewSet

Serializer

ProductImageSerializer

Classes in which the data received in the request is converted into an object and confirmed.

Parameter

Status

pkNot mandatory
productMandatory
imageMandatory
orderNot mandatory
sourceNot mandatory
modified_dateMandatory
created_dateMandatory

ProductVideoSerializer

Classes in which the data received in the request is converted into an object and confirmed.

Figure 4: ProductVideoSerializer

ParameterStatus
pkNot mandatory
productMandatory
videoMandatory
orderNot mandatory
modified_dateMandatory
created_dateMandatory

Service

ProductImageService

ProductImageService contains methods made updated on product images for a product. API endpoints use these services. These services enable the creation, updating and deletion of a product image. In addition, services include updating an image as a base image (other custom types), reordering images (change order field value) etc.

Figure 5: ProductImageService

ProductVideoService

ProductVideoService contains methods updated in product videos for a product. API endpoints use these services. These services enable the creation, updating and deletion of product videos.

Figure 6: ProductVideoService

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/

{
"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

ViewSet

DownloadableImageViewSet

These are the functions of creating, updating, deleting and downloading requests from the API. download is a detailed endpoint to download images from the ERP system.

Figure 7: DownloadableImageViewSet

Serializer

DownloadableImageSerializer

Classes in which the data received in the request is converted into an object and confirmed.

Figure 8: DownloadableImageSerializer

Parameter

Status

pk

Not mandatory
productMandatory
urlMandatory
orderNot mandatory
product_imageNot mandatory
image_typeMandatory
attribute_keyNot mandatory
retry_countMandatory
sourceNot mandatory
modified_dateMandatory
created_dateMandatory

Service

DownloadableImageService

All business process details in downloadable images made on services. API endpoints use these services to complete the respective business process.

Figure 9: DownloadableImageService