curl -X PUT "https://api.example.com/api/v1/product-images/1" \
-H "Content-Type: application/json" \
-d '{
"productId": 101,
"imageUrl": "https://example.com/images/sofa-front-updated.jpg",
"altText": "Modern grey sofa - updated front view",
"displayOrder": 1
}'
Updates an existing product image with the provided details.
Method and Path
PUT /api/v1/product-images/{id}
Path Parameters
The unique identifier of the product image to update
Request Body
ID of the product this image belongs to
URL of the product image. Must be a valid and accessible URL.
Alternative text description for accessibility
Order in which the image should be displayed. Lower numbers appear first.
Response
The updated product image object
Unique identifier for the product image
ID of the product this image belongs to
Alternative text description for accessibility
Order in which the image should be displayed
Response Codes
Product image successfully updated
Invalid request body or validation error
Product image with the specified ID was not found
Request Example
{
"productId": 101,
"imageUrl": "https://example.com/images/sofa-front-updated.jpg",
"altText": "Modern grey sofa - updated front view",
"displayOrder": 1
}
Response Example
{
"id": 1,
"productId": 101,
"imageUrl": "https://example.com/images/sofa-front-updated.jpg",
"altText": "Modern grey sofa - updated front view",
"displayOrder": 1
}
Error Response Examples
Validation Error
{
"status": 400,
"error": "Bad Request",
"message": "Validation failed",
"errors": [
{
"field": "imageUrl",
"message": "Image URL is required"
}
]
}
Not Found Error
{
"status": 404,
"error": "Not Found",
"message": "Product image not found with id: 999"
}
Usage Examples
Update Image URL
curl -X PUT "https://api.example.com/api/v1/product-images/1" \
-H "Content-Type: application/json" \
-d '{
"productId": 101,
"imageUrl": "https://example.com/images/sofa-new-photo.jpg",
"altText": "Modern grey sofa - front view",
"displayOrder": 1
}'
Update Alt Text
curl -X PUT "https://api.example.com/api/v1/product-images/1" \
-H "Content-Type: application/json" \
-d '{
"productId": 101,
"imageUrl": "https://example.com/images/sofa-front.jpg",
"altText": "Luxurious modern grey sofa with chrome legs - front view",
"displayOrder": 1
}'
Update Display Order
curl -X PUT "https://api.example.com/api/v1/product-images/1" \
-H "Content-Type: application/json" \
-d '{
"productId": 101,
"imageUrl": "https://example.com/images/sofa-front.jpg",
"altText": "Modern grey sofa - front view",
"displayOrder": 3
}'
Update Product Image with JavaScript
const imageData = {
productId: 101,
imageUrl: 'https://example.com/images/sofa-front-updated.jpg',
altText: 'Modern grey sofa - updated front view',
displayOrder: 1
};
fetch('https://api.example.com/api/v1/product-images/1', {
method: 'PUT',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(imageData)
})
.then(response => response.json())
.then(data => console.log('Updated:', data))
.catch(error => console.error('Error:', error));
Update Product Image with Python
import requests
image_data = {
'productId': 101,
'imageUrl': 'https://example.com/images/sofa-front-updated.jpg',
'altText': 'Modern grey sofa - updated front view',
'displayOrder': 1
}
response = requests.put(
'https://api.example.com/api/v1/product-images/1',
json=image_data
)
if response.status_code == 200:
updated_image = response.json()
print(f"Updated image: {updated_image['imageUrl']}")
else:
print(f"Error: {response.status_code}")
Common Use Cases
Reorder Product Images
Update the display order to change how images appear in the product gallery:
# Move an image to the first position
curl -X PUT "https://api.example.com/api/v1/product-images/3" \
-H "Content-Type: application/json" \
-d '{
"productId": 101,
"imageUrl": "https://example.com/images/sofa-detail.jpg",
"altText": "Sofa detail view",
"displayOrder": 1
}'
Update Image After Re-upload
Change the URL after uploading a higher quality image:
curl -X PUT "https://api.example.com/api/v1/product-images/1" \
-H "Content-Type: application/json" \
-d '{
"productId": 101,
"imageUrl": "https://example.com/images/sofa-front-hq.jpg",
"altText": "Modern grey sofa - front view",
"displayOrder": 1
}'
Improve Accessibility
Enhance alt text for better SEO and accessibility:
curl -X PUT "https://api.example.com/api/v1/product-images/1" \
-H "Content-Type: application/json" \
-d '{
"productId": 101,
"imageUrl": "https://example.com/images/sofa-front.jpg",
"altText": "Contemporary grey upholstered three-seater sofa with brushed metal legs and plush cushions",
"displayOrder": 1
}'