I would like to know how to retrieve products that belong to a specific category in Magento SOAP API V2, with WS-I compliance and also without.
Here's what I've tried in WS-I compliance mode:
$proxy = new SoapClient('http://foobar.local/api/v2_soap/?wsdl');
$sessionId = $proxy->login(array(
'username' => 'foo',
'apiKey' => 'bar'
));
$filters = array( 'complex_filter' =>
array(
array(
'key' => 'category_ids',
'value' => array( 'key' => 'like', 'value' => '%1%' )
)
)
);
$result = $proxy->catalogProductList(array('sessionId' => $sessionId->result, 'filters' => $filters));
var_dump($result->result);
I can use the complex filter to successfully filter by product_id
however this fails to work for category_ids as it has another nested level. How can I retrieve products via the Magento API for a certain category ID? Should I be using catalog_category.assignedProducts
?
Best Answer
As you already noted in your question, the preferred way of retrieving products which belong to a specific category is
catalogCategoryAssignedProducts
for SOAPv2 (see documentation here).catalogProductList
is a way of retrieving products by attributes.Please note that
catalogCategoryAssignedProducts
fetches only products from one specific category and not multiple ones.The SOAP calls according to documentation are:
SOAPv2:
SOAPv2 WS-I: