Product Image
This service has upsert logic. If a given product_sku
exists in the system, the product image will be updated with the given parameters. If there is no image for the product SKU, it will be created. Data that is not included in the request will be deleted even if it was added before.
Note: Image URLs must be accessible for "Omnitron" in order for the images to be uploaded to the CDN.
Parameter | Data Type | In | Required | Description |
api_token | string | header | YES | The API key of the customer account |
product_sku | string | body | YES | Product SKU |
images | dict | body | YES | Images dictionary. It has url and order keys |
url | string | body | YES | Image URL |
unit_type | string | body | Stocked quantity type. qty: Quantity | |
order | integer | body | Image order. Default_value = 0 | |
image_type | string | body | Default or swatch. Swatch is a thumbnail image which is used to show product variants on the website. Defaul_value = default |
Insert and Update Images
Request POST
It is used to replace existing downloadable_image
objects with new images or to add images to products that do not have images. Images of the product must be sent in a single request. When more than one image is wanted to be added, if any of them is wrong, none of the images will be added.
Downloadable image(s) the product has, but not in the request body, will be deleted.
Downloadable image(s) the product has also in the request body will be updated with order
and image_type
values.
Downloadable images just in the request body will be created.
import requests
import json
url = "https://{customer_api_url}/api/i1/downloadable_image/"
api_token = "f532e28df6e4d5fa4648a812018876da1bb9332d"
headers = {
'content-type': 'application/json',
'Authorization': 'Token {}'.format(api_token)
}
data = {
'product_sku': '1182701025',
'images': [
{'url': 'https://url/image1.png',
'order': 0
'image_type': 'swatch'
},
{'url': 'https://url/image2.png',
'order': 1
}
]
}
response = requests.post(url, headers=headers, data=json.dumps(data))
print(response.text)
Response
Returns the data of the successfully added images.
{
"product_sku": "1182701025",
"images": [
{
"id": 676599,
"url": "https://url/image1.png",
"order": 0,
"image_type": "swatch"
},
{
"id": 676600,
"url": "https://url/image2.png",
"order": 1,
"image_type": "default"
}
]
}
Retrieve Images
Request GET
In order to access the image data of all products, a request can be made without adding any parameters.
‘content_type’ header represents the response type.
‘Authorization’ header is a required header for authentication. You can retrieve api_token with login.
Path: api/i1/downloadable_image/
import requests
import json
url = "https://{customer_api_url}/api/i1/downloadable_image/"
api_token = "f532e28df6e4d5fa4648a812018876da1bb9332d"
headers = {
'content-type': 'application/json',
'Authorization': 'Token {}'.format(api_token)
}
response = requests.get(url, headers=headers)
print(response.text)
Response
When the request is sent without adding any parameters, the image data of all products will be listed on the basis of SKU.
“count” shows how many products exist in the system.
“next” shows the next page url to retrieve the desired image data.
“previous” shows the previous page url to retrieve the desired image data.
“results” shows every image property with detailed field descriptions.
Images are listed in the “images” area of each product.
{
"count": 2,
"next": null,
"previous": null,
"results": [
{
"product_sku": "1182701025",
"images": [
{
"id": 676599,
"url": "https://url/image1.png",
"order": 0,
"image_type": "swatch"
},
{
"id": 676600,
"url": "https://url/image2.png",
"order": 1,
"image_type": "default"
}
]
},
{
"product_sku": "7832783278",
"images": [
{
"id": 676601,
"url": "https://url/image3.png",
"order": 0,
"image_type": "swatch"
},
{
"id": 676602,
"url": "https://url/image4.png",
"order": 1,
"image_type": "default"
}
]
}
]
}
Retrieve All Images for Given SKU
Request GET
When you want to list images of a particular product, information can be accessed by adding product_sku
information as a query parameter.
‘content_type’ header represents the response type.
‘Authorization’ header is a required header for authentication. You can retrieve api_token with login.
Path: api/i1/downloadable_image/
import requests
import json
url = "https://{customer_api_url}/api/i1/downloadable_image/"
api_token = "f532e28df6e4d5fa4648a812018876da1bb9332d"
headers = {
'content-type': 'application/json',
'Authorization': 'Token {}'.format(api_token)
}
response = requests.get(url, headers=headers, params={"product_sku": "1182701025"})
print(response.text)
Response
The ID, URL, order and image_type
information of the images of the specified product will be listed as a response.
{
"count": 1,
"next": null,
"previous": null,
"results": [
{
"product_sku": "1182701025",
"images": [
{
"id": 676599,
"url": "https://url/image1.png",
"order": 0,
"image_type": "swatch"
},
{
"id": 676600,
"url": "https://url/image2.png",
"order": 1,
"image_type": "default"
}
]
}
]
}
Delete All Images
Request POST
Every image for a product with the given SKU can be removed with the following request:
Path: api/i1/downloadable_image/
import requests
import json
url = "https://{customer_api_url}/api/i1/downloadable_image/"
api_token = "f532e28df6e4d5fa4648a812018876da1bb9332d"
headers = {
'content-type': 'application/json',
'Authorization': 'Token {}'.format(api_token)
}
data = {
'product_sku': '1182701025',
'images': [
]
}
response = requests.post(url, headers=headers, data=json.dumps(data))
print(response.text)
Response
If the deletion is successful, the transmitted data will be displayed in the response.
{
"product_sku": "1182701025",
"images": [
]
}
Delete a Single Image
Request POST
To delete a single image for a product, an image list should be sent without the image to be deleted.
Path: api/i1/downloadable_image/
import requests
import json
url = "https://{customer_api_url}/api/i1/downloadable_image/"
api_token = "f532e28df6e4d5fa4648a812018876da1bb9332d"
headers = {
'content-type': 'application/json',
'Authorization': 'Token {}'.format(api_token)
}
response = requests.get(url, headers=headers, params={"product_sku": "1182701025"})
data = response.json()
data = data["results"][0]
data["images"].pop()
response = requests.post(url, headers=headers, data=json.dumps(data))
print(response.text)
Response
After the request is sent, all images belonging to the product will be sent as a response.
{
"product_sku": "1182701025",
"images": [
{
"id": 676599,
"url": "https://url/image1.png",
"order": 0,
"image_type": "default"
}
]
}
Update Order and Image Type
Request POST
To update any field, the POST request should be sent with the original data and the updated field.
Default order value is 0 if not sent with request.
Default image type value is default if not sent with request.
The data that already exists but is not included in the request for the update will be deleted.
Path: api/i1/downloadable_image/
import requests
import json
url = "https://{customer_api_url}/api/i1/downloadable_image/"
api_token = "f532e28df6e4d5fa4648a812018876da1bb9332d"
headers = {
'content-type': 'application/json',
'Authorization': 'Token {}'.format(api_token)
}
response = requests.get(url, headers=headers, params={"product_sku": "1182701025"})
data = response.json()
data = data["results"][0]
data["images"][0]["order"] = 5
data["images"][1]["order"] = 6
response = requests.post(url, headers=headers, data=json.dumps(data))
print(response.text)
Response
Edited or newly added data will be listed in the response.
{
"product_sku": "1182701025",
"images": [
{
"id": 676599,
"url": "https://url/image1.png",
"order": 5,
"image_type": "default"
},
{
"id": 676600,
"url": "https://url/image2.png",
"order": 6,
"image_type": "default"
}
]
}