Retrieving Product Attributes from Magento's V2 API
Note: This article was originally published at Planet PHP
on 12 July 2010.
I've been working with the API for Magento in recent weeks and I had a bit of a struggle explaining to the V2 API which attributes of a product I wanted to retrieve. Actually I had issues talking to the V2 API at all, but that's a different post so I'll skate over those for now. Instead I thought I'd share (or rather, record for the next time I have the same problem!) how to specify which attributes about a product to retrieve.It actually wasn't complicated but without V2 API documentation, it wasn't at all clear what to feed in to get the result I was looking for. It turns out you can just pass an array of desired attributes, shown here with the info method from the product_catalog:
A A // connect to soap server
A A $client = new SoapClient('http://magentoinstall.local/api/v2_soap?wsdl=1');
A A // log in
A A $session = $client-login('user', 'pass');
A A // product info
A A $attributes = new stdclass();
A A $attributes-attributes = array('product_title', 'description', 'short_description', 'price');
A A $list = $client-catalogProductInfo($session,, NULL, $attributes);
A
There were two tricks - one was realising that I could pass that final (undocumented) argument, and the other was understanding how to format that. Hopefully anyone doing battle with the same thing will find this post and get over this little challenge much faster than I did :)


