How to pull custom product attribute using SOAP API in Magento

In: Feeling guru|Techie Daw

12 Nov 2016

When extracting a product attribute data using SOAP, the usual approach is to create a standard class and identify the common fields in the attributes property as shown below:

$proxy = new SoapClient('http://your.magento.domain/api/v2_soap/?wsdl');
$sessionId = $proxy->login('username', 'password!');
$product = new stdclass();
$product->attributes = array(
     'description',
     'short_description',
     'price',
     'custom_attribute_code'
);
$data = $proxy->catalogProductInfo($sessionId, $sku, null, $product);
var_dump($data);

The above var_dump() would show the values of requested fields except the custom_attribute_code. The reason for this is because a custom product attribute is available in additional_attributes property instead.

Get custom product attribute:

To get the value of custom_attribute_code, use the following code:

$proxy = new SoapClient('http://your.magento.domain/api/v2_soap/?wsdl');
$sessionId = $proxy->login('username', 'password!');
$product = new stdClass();
$product->additional_attributes = array('custom_attribute_code');
$data = $proxy->catalogProductInfo($sessionId, $sku, null, $product);

About the author

Richard Feraro is a Magento Enterprise Certified developer from Manila, Philippines with 14 years of solid open-source development experience using Linux, Apache, MySQL & PHP.

Comment Form

About my blog

This blog is targeted towards all levels of developers and also designers. Various topics are discussed such as Magento, PHP & MySQL, jQuery, WordPress, CSS and HTML.

Booking.com

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 24 other subscribers

WordPress + Magento

Recent Trackbacks

Archives

Disclaimer

All entries in this blog are my opinion and don't necessarily reflect the opinion of my employer or my mom.