1

I have found API calls for product listing like

http://xxxxxx.com/api/rest/products?limit=100

and

http://xxxxxx.com/api/rest/products

by default its 10 products and after passing limit its giving specific records, but can we get all the products without using limit and page params?

2

While it is not wise to do, yes, you can get all of the products in the system in one call. All you have to do is send the query parameter searchCriteria=0 but, you will need to be Admin Authenticated though.

You do it like this:

curl -X GET http://YOURMAGENTOURL/rest/V1/products?searchCriteria=0 -H 'Content-type: application/json' -H "Authorization: Bearer YOURAPIKEY"
1

It is not safe to remove limit completely, because your process will get out of memory and fail to return any products on real Magento store one day (when catalog grows to some extent). This is acceptable thing to do only during development for testing purposes.

Instead, pagination mechanisms provided by Magento (page and limit params) should be used to retrieve full catalog by chunks. Every chunk should ideally be processed by the client before requesting the next one to avoid memory issues on the client side. This is the only reliable approach.

0

Please modify some code in file : Mage_Catalog_Model_Api2_Product_Rest

Go to this class and find the function _retrieveCollection() and update code as per below.

Updated code:

protected function _retrieveCollection()
{  
    /** @var $collection Mage_Catalog_Model_Resource_Product_Collection */
    $collection = Mage::getResourceModel('catalog/product_collection');
    $store = $this->_getStore();
    $entityOnlyAttributes = $this->getEntityOnlyAttributes($this->getUserType(),
        Mage_Api2_Model_Resource::OPERATION_ATTRIBUTE_READ);
    $availableAttributes = array_keys($this->getAvailableAttributes($this->getUserType(),
        Mage_Api2_Model_Resource::OPERATION_ATTRIBUTE_READ));
    // available attributes not contain image attribute, but it needed for get image_url
    $availableAttributes[] = 'image';
    $collection->addStoreFilter($store->getId())
        ->addPriceData($this->_getCustomerGroupId(), $store->getWebsiteId())
        ->addAttributeToSelect(array_diff($availableAttributes, $entityOnlyAttributes))
        ->addAttributeToFilter('visibility', array(
            'neq' => Mage_Catalog_Model_Product_Visibility::VISIBILITY_NOT_VISIBLE))
        ->addAttributeToFilter('status', array('eq' => Mage_Catalog_Model_Product_Status::STATUS_ENABLED));
    $dftAll = $collection->getSize();
    $this->_applyCategoryFilter($collection);
    $this->_applyCollectionModifiers($collection);
    $pageSize = $this->getRequest()->getPageSize();
    if (null == $pageSize) {
        $collection->setPageSize($dftAll); 
    }
    $products = $collection->load();

    /** @var Mage_Catalog_Model_Product $product */
    foreach ($products as $product) {
        $this->_setProduct($product);
        $this->_prepareProductForResponse($product);
    }
    return $products->toArray();
}
  • i am getting 404 error, how can i solve the issue, abc.com/api/rest/products?limit=2 – Gem Oct 26 '18 at 9:25
  • Have you given permission admin side under the REST Roles for the gust user? – Abdul Oct 26 '18 at 11:35
  • yes i did that. – Gem Oct 26 '18 at 11:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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