Product Images API
This is an old revision of the document!
Allows to work with product images’ gallery
Module: Mage_Catalog
Resource: catalog_product_attribute_media
Aliases:
- product_attribute_media
- product_media
Methods |
catalog_product_attribute_media.currentStore |
Set/Get current store view
Return: int
Arguments:
- mixed storeView - store view code or ID (optional)
Aliases:
- product_attribute_media.currentStore
- product_media.currentStore
catalog_product_attribute_media.list |
Retrieve product image list
Return: array
Arguments:
- mixed product - product ID or Sku
- mixed storeView - store view ID or code (optional)
Aliases:
- product_attribute_media.list
- product_media.list
catalog_product_attribute_media.info |
Retrieve product image data
Return: array
Arguments:
- mixed product - product ID or Sku
- string file - image file name
- mixed storeView - store view ID or code (optional)
Aliases:
- product_attribute_media.info
- product_media.info
catalog_product_attribute_media.types |
Retrieve product image types (image, small_image, thumbnail, etc...)
Return: array
Arguments:
- int setId - product attribute set ID
Aliases:
- product_attribute_media.types
- product_media.types
catalog_product_attribute_media.create |
Upload new product image
Return: string - image file name
Arguments:
- mixed product - product ID or code
- array data - image data. requires file content in base64, and image mime-type. \ Example: array(’file’ ⇒ array(’content’ ⇒ base64_encode($file), ‘mime’ ⇒ ‘type/jpeg’)
- mixed storeView - store view ID or code (optional)
Aliases:
- product_attribute_media.create
- product_media.create
catalog_product_attribute_media.update |
Update product image
Return: boolean
Arguments:
- mixed product - product ID or code
- string file - image file name
- array data - image data (label, position, exclude, types)
- mixed storeView - store view ID or code (optional)
Aliases:
- product_attribute_media.update
- product_media.update
catalog_product_attribute_media.remove |
Remove product image
Return: boolean
Arguments:
- mixed product - product ID or Sku
- string file - image file name
Aliases:
- product_attribute_media.remove
- product_media.remove
Faults |
| Fault Code | Fault Message |
|---|---|
| 100 | Requested store view not found. |
| 101 | Product not exists. |
| 102 | Invalid data given. Details in error message. |
| 103 | Requested image not exists in product images’ gallery. |
| 104 | Image creation failed. Details in error message. |
| 105 | Image not updated. Details in error message. |
| 106 | Image not removed. Details in error message. |
| 107 | Requested product doesn’t support images |
Examples |
Example 1. Working with product images |
- $proxy = new SoapClient('http://magentohost/api/soap/?wsdl');
- $sessionId = $proxy->login('apiUser', 'apiKey');
- $newImage = array(
- 'file' => array(
- 'content' => base64_encode(file_get_contents('product.jpg')),
- 'mime' => 'image/jpeg'
- ),
- 'label' => 'Cool Image Througth Soap',
- 'position' => 2,
- 'types' => array('small_image'),
- 'exclude' => 0
- );
- $imageFilename = $proxy->call($sessionId, 'product_media.create', array('Sku', $newImage));
- var_dump($imageFilename);
- // Newly created image file
- var_dump($proxy->call($sessionId, 'product_media.list', 'Sku'));
- $proxy->call($sessionId, 'product_media.update', array(
- 'Sku',
- $imageFilename,
- array('position' => 2, 'types' => array('image') /* Lets do it main image for product */)
- ));
- // Updated image file
- var_dump($proxy->call($sessionId, 'product_media.list', 'Sku'));
- // Remove image file
- $proxy->call($sessionId, 'product_media.remove', array('Sku', $imageFilename));
- // Images without our file
- var_dump($proxy->call($sessionId, 'product_media.list', 'Sku'));


