Question

I am new to Magento API. I am developing Android application using SOAP v2 API. I am able to get login successfully and get session id. By using this session id I am able to get the list of products which are in my Magento web.

Now my problem is, I am getting approximately 850 products, so web service is getting little more time to response. I want to set limit in the request so that I gets only 20 records in each request. I have used filters but I don't think it will help me to solve my problem.

Was it helpful?

Solution

Unfortunately it isn't possible out of the box. You are right, filters are only used to filter attributes and there is no "limit" parameter

Arguments:

Type   | Name      | Description
string | sessionId | Session ID
array  | filters   | Array of filters by attributes (optional)
string | storeView | Store view ID or code (optional)

Source: http://www.magentocommerce.com/api/soap/catalog/catalogProduct/catalog_product.list.html

Looking at the source code of Mage_Catalog_Model_Product_Api confirms it:

/**
 * Retrieve list of products with basic info (id, sku, type, set, name)
 *
 * @param null|object|array $filters
 * @param string|int $store
 * @return array
 */
public function items($filters = null, $store = null)
{
    $collection = Mage::getModel('catalog/product')->getCollection()
        ->addStoreFilter($this->_getStoreId($store))
        ->addAttributeToSelect('name');

    /** @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()
        );
    }
    return $result;
}

The collection gets filtered by store and by attributes and that's it. No way to further manipulate it. What you'd need to do is write an own API model that extends this class and adds its own method itemsWithLimit() with an additional parameter.

Update by request

if using the REST API with OAuth is an option, you actually can provide a limit:

Additional Information

You can define the limit of items returned in the response by passing the limit parameter. By default, 10 items are returned and the maximum number is 100 items. You can also define the page number by passing the page parameter. Example:

http://magentohost/api/rest/products?page=2&limit=20

Authorization header will be required for Admin and Customer user types. The following parameters must be provided in the Authorization header for the call:

  • oauth_consumer_key - the Consumer Key value provided after the registration of the application.
  • oauth_nonce - a random value, uniquely generated by the application.
  • oauth_signature_method - name of the signature method used to sign the request. Can have one of the following values: HMAC-SHA1, RSA-SHA1, and PLAINTEXT.
  • oauth_signature - a generated value (signature).
  • oauth_timestamp - a positive integer, expressed in the number of seconds since January 1, 1970 00:00:00 GMT.
  • oauth_token - the oauth_token value (Request Token).
  • oauth_version - OAuth version.

Source: http://www.magentocommerce.com/api/rest/introduction.html#RESTAPIIntroduction-Products

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top