Add product image
Add a picture to a product, from a URL (JSON) or an upload (multipart field image)
https://s.zo.sa/api/public/v1 /products/{id}/images products.read_writeIdempotency-Key supportedAn upload is stored at once and answered 201 with the picture. A URL is copied in the background: 202 with the pending entry, which the product lists in images_pending until the copy joins images (last in the order). Links still pending count against the 10 pictures a product may have.
Request
Path parameters
| Name | Type | Required | Description |
|---|---|---|---|
id | integer | required | At least 1 |
Headers
| Name | Type | Required | Description |
|---|---|---|---|
Idempotency-Key | string | 1 to 120 visible ASCII characters. A write sent again with the same key runs once; the retry gets the first answer back with the header Idempotent-Replayed: true. Use a new key for each new write. 1 to 120 characters |
Request body
As application/json
A picture the store copies from a public http(s) address (ports 80 and 443 only). A link that is not http(s), uses another port, or names a private, loopback, link-local or reserved address is refused with 422. The copy runs in the background after the answer: the link shows in the product's images_pending until it joins images. A name that resolves to a private address, or a file that is not a JPEG, PNG, WebP or GIF of at most 15 MB, ends as status failed with error image_unreachable. A store has at most 50 links waiting at a time: a write that would pass that is refused with 429 images_queue_full and a Retry-After header, and changes nothing.
urlstring (uri)required
As multipart/form-data
imagestring (binary)requiredJPEG, PNG or WebP, at most 10 MB.
Upload a file instead
curl -sS -X POST "https://s.zo.sa/api/public/v1/products/501/images" \
-H "Authorization: Bearer $ZO_API_KEY" \
-H "Accept: application/json" \
-H "Idempotency-Key: erp-image-TSHIRT-BLUE-M-2-upload" \
-F "image=@photo.jpg"{
"data": {
"id": 1,
"url": "https://example.com",
"alt": null,
"sort": 1
}
}Example generated from the schema.
cURL
curl -sS -X POST "https://s.zo.sa/api/public/v1/products/501/images" \
-H "Authorization: Bearer $ZO_API_KEY" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: erp-image-TSHIRT-BLUE-M-2" \
-d '{
"url": "https://cdn.example.com/products/tshirt-blue-back.jpg"
}'JavaScript
const response = await fetch('https://s.zo.sa/api/public/v1/products/501/images', {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.ZO_API_KEY}`,
Accept: 'application/json',
'Content-Type': 'application/json',
'Idempotency-Key': 'erp-image-TSHIRT-BLUE-M-2',
},
body: JSON.stringify({
"url": "https://cdn.example.com/products/tshirt-blue-back.jpg"
}),
});
console.log(response.status, await response.json());PHP
<?php
$ch = curl_init('https://s.zo.sa/api/public/v1/products/501/images');
curl_setopt_array($ch, [
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . getenv('ZO_API_KEY'),
'Accept: application/json',
'Content-Type: application/json',
'Idempotency-Key: erp-image-TSHIRT-BLUE-M-2',
],
CURLOPT_POSTFIELDS => json_encode([
'url' => 'https://cdn.example.com/products/tshirt-blue-back.jpg',
]),
]);
$body = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
echo $status, PHP_EOL, $body, PHP_EOL;Python
import os
import requests
response = requests.post(
"https://s.zo.sa/api/public/v1/products/501/images",
headers={
"Authorization": f"Bearer {os.environ['ZO_API_KEY']}",
"Accept": "application/json",
"Idempotency-Key": "erp-image-TSHIRT-BLUE-M-2",
},
json={
"url": "https://cdn.example.com/products/tshirt-blue-back.jpg",
},
timeout=30,
)
print(response.status_code, response.json())A public link, copied in the background: the answer is 202 with the pending entry.
{
"data": {
"source_url": "https://cdn.example.com/products/tshirt-blue-back.jpg",
"status": "pending",
"error": null
}
}Example. The link waits in images_pending until its copy joins images, then product.updated is sent.
Responses
Response schema
dataobjectrequired4 fields
idintegerrequiredurlstring (uri)requiredaltstringrequirednullableReserved; null until images carry alt text.sortintegerrequired
Response schema
dataobjectrequired3 fields
source_urlstring (uri)requiredThe link as it was sent.statusstringrequirederrorstringrequirednullableWhy a failed link was not copied; null while pending. too_many_images when the product already had 10 pictures by the time the copy finished; copy_failed when the copy job itself stopped, or ran out of time before this link (a job downloads for 60 seconds at most, 10 per link), so send it again in a new write.
An error object: {"error": {"code", "message", "fields"}}.
An error object: {"error": {"code", "message", "fields"}}.
An error object: {"error": {"code", "message", "fields"}}.
An error object: {"error": {"code", "message", "fields"}}.
An error object: {"error": {"code", "message", "fields"}}.
An error object: {"error": {"code", "message", "fields"}}.
An error object: {"error": {"code", "message", "fields"}}.