Product Images API

Last modified by danshields on Tue, June 8, 2010 08:10
Source|Old Revisions  

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

  1. $proxy = new SoapClient('http://magentohost/api/soap/?wsdl');
  2. $sessionId = $proxy->login('apiUser', 'apiKey');
  3.  
  4. $newImage = array(
  5.     'file' => array(
  6.         'name' => 'file_name',
  7.         'content' => base64_encode(file_get_contents('product.jpg')),
  8.         'mime'    => 'image/jpeg'
  9.     ),
  10.     'label'    => 'Cool Image Through Soap',
  11.     'position' => 2,
  12.     'types'    => array('small_image'),
  13.     'exclude'  => 0
  14. );
  15.  
  16. $imageFilename = $proxy->call($sessionId, 'product_media.create', array('Sku', $newImage));
  17.  
  18.  
  19. var_dump($imageFilename);
  20.  
  21. // Newly created image file
  22. var_dump($proxy->call($sessionId, 'product_media.list', 'Sku'));
  23.  
  24. $proxy->call($sessionId, 'product_media.update', array(
  25.     'Sku',
  26.     $imageFilename,
  27.     array('position' => 2, 'types' => array('image') /* Lets do it main image for product */)
  28. ));
  29.  
  30. // Updated image file
  31. var_dump($proxy->call($sessionId, 'product_media.list', 'Sku'));
  32.  
  33. // Remove image file
  34. $proxy->call($sessionId, 'product_media.remove', array('Sku', $imageFilename));
  35.  
  36. // Images without our file
  37. var_dump($proxy->call($sessionId, 'product_media.list', 'Sku'));



 

Magento 2 GitHub Repository

Magento Job Board - Some sort of tag line goes here

Latest Posts| View all Jobs