1

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.

  • You might be using default web Service of magento, you can create a module as per your need for getting products with limit – Rahul Kumar Das Feb 6 '15 at 8:47
1

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

  • @fschmenfler:Thanks for the reply. Can we set limit using REST api? – Kushal Shah Feb 6 '15 at 8:13
  • See updated answer – Fabian Schmengler Feb 6 '15 at 8:20
  • OK will go through it in detail. Looks like it solve my issue. Thanks once again. – Kushal Shah Feb 6 '15 at 8:24
  • Please accept the answer if it helped you solving your problem. This way the question will no longer be counted as "unanswered" (magento.SE needs a higher rate of answered questions to go out of beta eventually) – Fabian Schmengler Feb 14 '15 at 21:17

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.