Sifr Wahid Developers

API reference / Products

Add product image

Add a picture to a product, from a URL (JSON) or an upload (multipart field image)

POST https://s.zo.sa/api/public/v1/products/{id}/images
Scope products.read_writeIdempotency-Key supported

An 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

NameTypeRequiredDescription
idintegerrequiredAt least 1

Headers

NameTypeRequiredDescription
Idempotency-Keystring1 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

application/json or multipart/form-data required

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
    Up to 2000 characters

As multipart/form-data

  • imagestring (binary)required
    JPEG, PNG or WebP, at most 10 MB.

Upload a file instead

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 "Idempotency-Key: erp-image-TSHIRT-BLUE-M-2-upload" \
  -F "image=@photo.jpg"
Response 201
{
  "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.

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

201The uploaded picture, last in the product order.
Response schema
  • dataobjectrequired
    4 fields
    • idintegerrequired
    • urlstring (uri)required
    • altstringrequirednullable
      Reserved; null until images carry alt text.
    • sortintegerrequired
202The URL is accepted and copied in the background.
Response schema
  • dataobjectrequired
    3 fields
    • source_urlstring (uri)required
      The link as it was sent.
    • statusstringrequired
      One of pending, failed
    • errorstringrequirednullable
      Why 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.
      One of image_unreachable, too_many_images, copy_failed
401Missing, unknown, revoked or expired key.

An error object: {"error": {"code", "message", "fields"}}.

402The store's plan does not include this feature (error code feature_locked, with the feature and the plan that has it). Every operation answers it with feature public_api when the key's store is not on the Pro plan.

An error object: {"error": {"code", "message", "fields"}}.

403The key lacks the scope (code insufficient_scope, naming it in scope), the caller's address is not allowed (ip_not_allowed), or the store is suspended (store_suspended: reads stay allowed, every write answers this).

An error object: {"error": {"code", "message", "fields"}}.

404No such row in this store (code not_found).

An error object: {"error": {"code", "message", "fields"}}.

409A write with the same Idempotency-Key is still running (code duplicate_request); retry shortly.

An error object: {"error": {"code", "message", "fields"}}.

422The body is invalid (code validation_failed). fields names each invalid input by its path in the body, such as variants.0.sku or images.1.url.

An error object: {"error": {"code", "message", "fields"}}.

429Too many requests (code rate_limited); see Retry-After.

An error object: {"error": {"code", "message", "fields"}}.