0

I am attempting to add an image to a magento product, through the API.. The images are already on the magento server so the idea of encoding them in base64 and then creating new images just seems smelly.

Does anyone know if there's a way to link an image to a product if the image already exists?

Please note. I'm looking for existing API methods. Sadly I can't write new PHP code to extend the API because I don't have access to the magento box. This is for a third party app that is slated to integrate with an existing magento site.

1 Answer 1

1

If you are working with the Magento WSDL you can use the product_media API. Documentation on this you can find here.

You will need the product SKU and the base64 encoded contents of the image. With that you can perform an API call to add the image to the product.

$image_data = array(
    'file' => array(
        'name' => 'mynewimage',
        'content' => base64_encode(file_get_contents('[the image file]')),
        'mime'    => 'image/jpeg'
    ),
    'label'    => 'My Product image',
    'position' => 1,
    'types'    => array('thumbnail','small_image','image'),
    'exclude'  => 0
);

$proxy->call($session_id, 'product_media.create', array('[product SKU]', $image_data));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.