2

I cannot find any documentation (other than the WSDL itself) that provides a working example of how to filter a SOAP API_v2 catalogProductList.

I have a list of skus and I want to filter the list with nin (not in) so that the response gives me all products other than what I have in my skus.

$skus = array('1','2','3');
$filter = array(
    'sku' => array('nin' => $skus)
)
$productList = $client->catalogProductList($session, $filter);

// Returns all products in the store instead of filtered list.
Zend_Debug::dump($productList);

I have also see the $filter being built with complex_filters that uses a different array structure, but I don't understand what the difference is.

How do I simply filter an API product list using the nin method?


EDIT

Trying with complex_filters, using 'eq' works, but not 'nin':

// this returns a single product with sku 12345
$filter = array(
    'complex_filter' => array(
        array('key' => 'sku', 'value' => array('key' => 'eq', 'value' => '12345'))
    )
);

// This results in an error - "Notice: Array to string conversion  in ..."
$filter = array(
    'complex_filter' => array(
        array('key' => 'sku', 'value' => array('key' => 'nin', 'value' => array('12345', '67890'))
    )
);

2 Answers 2

2

API V2 queries use a "complex filter" for advanced queries. Their syntax is a bit different. Here's a complex filter query for your sample:

$filter = array(
  array(
    'complex_filter' => array(
      array(
        'key' => 'sku',
        'value' => array('key' => 'nin', 'value' => '1,2,3')
      )
    )
  )
);

$productList = $client->catalogProductList($session, $filter);

More query samples are available on the catalogProduct API Doc page

1
  • As I just edited and figured out, the value needs to be a comma separated string not an array. Thanks for the documentation Magento!
    – pspahn
    Jul 24, 2015 at 19:28
0

I think you should use

array('nin'=>$skus) instead of array('nin',$skus)

Then it should work!

1
  • That's just a typo in my question.
    – pspahn
    Jul 24, 2015 at 19:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.