Magento Themes and Magento Extensions

Magento API Call for Getting Product List with Filters

Share

Magento Provides the Web Services API Features to allow other systems to communicate with the magento store.
If you are new to magento webservices please visit the official site links

  • Web Services Information
  • Magento Core API

While there are methods available to fetch product from outside magento.
But there is no example given on the official site on how to use the method catalog.product_list with Filters.
Recently while Working with this Method I got unexpected results, either
it returns all the product lists without filtering or it shows fault exception messages like
Unknown error or Requested Store view not found etc.

After Carefully Inspecting the Magento API code finally i got the Product list results with filters applied.
So I would like to share this Solution.

//Sample Code For Soap Client
$client = new SoapClient(‘http://example.com/api/?wsdl’);
// login

try {
$session = $client->login(‘your_api_username’, ‘your_api_key’);
$filters = array(
array(‘sku’ => array(‘like’=>’test%’),’name’=>array(‘eq’=>’Test’))
);

$message=$client->call($session,’catalog.product.list’,$filters);
print_r($message);
}
catch(Exception $fault)
{
echo $fault->getMessage();
}

// Sample Code For XMLRPC client

$client = new Zend_XMLRPC_Client(‘http://example.com/api/xmlrpc’);
$session = $client->call(‘login’, array(‘your_api_username’, ‘your_api_key’));
$filters = array(
array(‘sku’ => array(‘like’=>’test%’),’name’=>array(‘eq’=>’Test’))
);

try {
$message = $client->call(‘call’, array($session, ‘catalog_product.list’, $filters));
print_r($message);
} catch (Exception $fault) {
echo $fault->getMessage();
}

Leave a Reply

You must be logged in to post a comment.