How to add constraint parameter in Magento API call
I am creating a web service for my store. I am using magento API to collect a list of products from a store. But it displays all 500 records. And I want 25 entries per page. What to add to the API call? Or What filter will be applied for this?
// create a soap object $ proxy = new SoapClient (' http: // localhsot / magento / api / soap /? wsdl ');
// create authorized session id using api user name and api key
// $sessionId = $proxy->login('apiUser', 'apiKey');
$sessionId = $proxy->login('test_admin', '12345678');
$filters = array(
);
// Get list of product
$productlist = $proxy->call($sessionId, 'product.list', array($filters));
print_r($productlist );
a source to share
I know this is an old question, but I was struggling with this. I created my own SOAP API endpoint, which is exactly the same as the default catalogProductList function, but has an additional parameter. See the code below:
$collection = Mage::getModel('catalog/product')->getCollection()
->addStoreFilter($this->_getStoreId($store))
->addAttributeToSelect('name');
if($limit) {
$collection->setOrder('updated_at', 'ASC');
$collection->setPageSize($limit);
}
/** @var $apiHelper Mage_Api_Helper_Data */
$apiHelper = Mage::helper('api');
$filters = $apiHelper->parseFilters($filters, $this->_filtersMap);
try {
foreach ($filters as $field => $value) {
$collection->addFieldToFilter($field, $value);
}
} catch (Mage_Core_Exception $e) {
$this->_fault('filters_invalid', $e->getMessage());
}
$result = array();
foreach ($collection as $product) {
$result[] = array(
'product_id' => $product->getId(),
'sku' => $product->getSku(),
'name' => $product->getName(),
'set' => $product->getAttributeSetId(),
'type' => $product->getTypeId(),
'category_ids' => $product->getCategoryIds(),
'website_ids' => $product->getWebsiteIds(),
'updated_at' => $product->getUpdatedAt(),
'created_at' => $product->getCreatedAt()
);
}
return $result;
And from there we track the last updated_at value and use it as a filter to get the next [LIMIT] items. By default updated_at and created_at are not in the response and the list is not ordered by updated_at, so I added this.
a source to share