1

i have use this code:

$proxy = new SoapClient('http://magentohost/api/soap/?wsdl');
$sessionId = $proxy->login('apiUser', 'apiKey');

$productId = 2;
$file = array(
    'content' => '/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAIBAQIBAQICAgICAgICAwUDAwMDAwYEBAMFBwYHBwcGBwcICQsJCAgKCAcHCg0KCgsMDAwMBwkODw0MDgsMDAz/2wBDAQICAgMDAwYDAwYMCAcIDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAz/wAARCAAXABcDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oADAMBAAIRAxEAPwDLooor8XP4DCiiigAooooAKKKKAP/Z',
    'mime' => 'image/jpeg'
);

$result = $proxy->catalogProductAttributeMediaCreate(
    $session,
    $productId,
    array('file' => $file, 'label' => 'Label', 'position' => '100', 'types' => array('thumbnail'), 'exclude' => 0)
);

but image not added in product ,, can any one guide me how can i add images with products using soap api ?

1 Answer 1

0

Please try with below example :

https://devdocs.magento.com/guides/m1x/api/soap/catalog/catalogProductAttributeMedia/productImages.html

 $proxy = new SoapClient('http://magentohost/api/soap/?wsdl');
    $sessionId = $proxy->login('apiUser', 'apiKey');

    $newImage = array(
        'file' => array(
            'name' => 'file_name',
            'content' => base64_encode(file_get_contents('product.jpg')),
            'mime'    => 'image/jpeg'
        ),
        'label'    => 'Cool Image Through 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'));

hope it will help you.

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.