Skip to main content

Create Product Image

Create a new product image.

HTTP Request

POST/api/products/:product_id/images

Path Parameters

ParameterTypeRequiredDescription
product_idintegerYesThe unique identifier of the product

Authorization

Authorization

  • Required: Yes
  • Permission: Staff or Admin
  • Authentication: Token-based (Authorization: Token <your_api_key>)

Request Body

FieldTypeRequiredDescription
imageFileYesImage file to upload
alt_textStringNoAlternative text for the image
is_primaryBooleanNoWhether this should be the primary product image (default: false)
orderIntegerNoDisplay order of the image (default: 0)

Example Requests

1import requests
2
3# Upload a new product image
4with open('product_image.jpg', 'rb') as image_file:
5  files = {'image': image_file}
6  data = {
7      'alt_text': 'Product front view',
8      'is_primary': True,
9      'order': 1
10  }
11  response = requests.post(
12      'http://www.example.com/api/products/123/images',
13      files=files,
14      data=data,
15      headers={'Authorization': 'Token <your_api_key>'}
16  )
17print(response.json())
18
19# Upload additional image
20with open('product_side.jpg', 'rb') as image_file:
21  files = {'image': image_file}
22  data = {
23      'alt_text': 'Product side view',
24      'order': 2
25  }
26  response = requests.post(
27      'http://www.example.com/api/products/123/images',
28      files=files,
29      data=data,
30      headers={'Authorization': 'Token <your_api_key>'}
31  )
32print(response.json())

Status Codes

CodeDescription
201Product image created successfully
400Bad Request - Invalid input or file format
401Unauthorized - Invalid or missing API key
403Forbidden - Access denied
404Not Found - Product not found
413Payload Too Large - File size exceeds limit

Response Fields

FieldTypeDescription
idintegerUnique identifier for the image
typestringImage type (e.g., "JPEG", "PNG", "WEBP")
userobjectUser who uploaded the image
namestringOriginal filename of the image
fstringFile URL/path
sizeintegerFile size in bytes
descriptionstringImage description
widthintegerImage width in pixels
heightintegerImage height in pixels
human_readable_sizestringHuman-readable file size (e.g., "2.5 MB")
modestringImage color mode (e.g., "RGB", "CMYK")
created_atdatetimeImage upload timestamp
updated_atdatetimeImage last update timestamp

User Data Structure

FieldTypeDescription
idintegerUnique ID of the user
usernamestringUsername of the user
full_namestringFull name of the user