Magento API problem setting additional_attributes
For some reason, it’s damn hard to get the additional_attributes
set via Magento’s v2 API. Even the example code in their API docs doesn’t cover it. After trying many permutations, I finally managed to get it working with the following snippet of code:
<?php
$soapopts = array('trace' => 1, 'exceptions' => 1, 'features' => SOAP_SINGLE_ELEMENT_ARRAYS); $client = new SoapClient ( 'http://www.yourmagentosite.com/api/v2_soap/?wsdl', $soapopts); $session = $client->login ( 'apiuser', 'apipassword' );
$productData = (object)array( 'additional_attributes' => (object)array( 'single_data' => array( (object)array( 'key' => 'custom_image_url', 'value' => 'http://www.yourmagentosite.com/nicepic.jpg', ), ), ), ); $result = $client->catalogProductUpdate($session, 'abjb91', $productData); print $client->__getLastRequest(); var_dump($result);