2
votes

I've been trying to import several thousand product images into a Magento 1.8.1.0 website using the SOAP API.

Although some have been imported, several hundred were not.

To try and find where this has happened I am using the following API command:

catalog_product_attribute_media.list

This is returning an error for some SKU's: "Product not exists". This is a genuine API error documented at http://www.magentocommerce.com/wiki/doc/webservices-api/api/catalog_product_attribute_media#faults

However, the SKU's where this is happening definitely exist within Magento, as I can search for them and see them in the Admin panel.

$result = $client->call($session, 'catalog_product_attribute_media.list', '452103');

The above code will cause an Exception saying "Product not exists" meaning it can't find anything for the SKU 452103. But if I search for SKU 452103 in the Admin panel it's there!

What's strange is that if I get the Magento Product ID for that SKU (in the above example it happens to be 3478) and run the following it works without error:

$result = $client->call($session, 'catalog_product_attribute_media.list', '3478');

Does anyone know what I'm doing wrong or why this might happen? The API documentation says what I'm passing as the second parameter to call() can be either the Product ID or the SKU.

I can only use the SKU in practice because my source data doesn't know what the Magento Product ID's are, but the SKU has been imported without modification. The code above where I've used Product ID = 3478 is just something I put to test whether it would output anything but I had to find this Product ID manually, which isn't practical for the number of images I need to fix.

1

1 Answers

2
votes

Please read the documentation for the API: http://www.magentocommerce.com/api/soap/catalog/catalogProductAttributeMedia/catalog_product_attribute_media.list.html

You will see there is a fourth parameter identifierType which says 'Defines whether the product ID or SKU is passed in the 'product' parameter'.

Every time you make your call at the moment the API is assuming it's the ID of the product. So to make it work by SKU only you should use the following;

$result = $client->call($session, 'catalog_product_attribute_media.list', '452103', 'sku');

There are numerous more API calls (product related) that all work in the same way but by default magento will always assume your using the product ID and not SKU unless you specify the identifier type.