Magento SOAP API Product List Pagination

Magento SOAP API Product List Pagination

August 15, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento SOAP API Product List Pagination

Magento SOAP API Product List Pagination: A Comprehensive Guide

Are you facing challenges when trying to read the list of products from Magento over the SOAP API? You’re not alone. In this post, we’ll explore how to successfully implement pagination for your product retrieval process without exhausting your memory.

The Memory Exhaustion Problem

You’ve likely encountered the dreaded “Allowed memory size exhausted” error when trying a simple catalogProductList call:

$filters = new Varien_Simplexml_Element('<filters/>');
$products = $proxy->call($sessionId, 'catalog_product.list', array('filters' => $filters));

This happens because Magento loads all products into memory at once when no filters are applied. If you have a large catalog, this will quickly lead to an out-of-memory error.

The Complex Filter Conundrum

Your attempt at adding pagination by specifying complex filters is a step in the right direction:

$filters = new Varien_Simplexml_Element('<filters/>');
$complexFilter1 = new Varien_Simplexml_Element('<complex_filter/>');
$associativeEntity1 = new Varien_Simplexml_Element('<associative_entity/>');
$associativeEntity1->key = 'gt';
$associativeEntity1->value = 400;
$complexFilter1->key = 'product_id';
$complexFilter1->value = $associativeEntity1;

$complexFilter2 = new Varien_Simplexml_Element('<complex_filter/>');
$associativeEntity2 = new Varien_Simplexml_Element('<associative_entity/>');
$associativeEntity2->key = 'lt';
$associativeEntity2->value = 1000;
$complexFilter2->key = 'product_id';
$complexFilter2->value = $associativeEntity2;

$filters->appendChild($complexFilter1);
$filters->appendChild($complexFilter2);

$products = $proxy->call($sessionId, 'catalog_product.list', array('filters' => $filters));

However, you’re right that only the second filter is applied. This happens because Magento processes complex filters sequentially, and if a filter matches too many results, it stops processing the subsequent ones to prevent memory issues.

The Category Assignment Challenge

Your idea of reading the category tree and assigned products is valid but comes with its own difficulties. Products can be assigned to multiple categories or none at all. This could lead to missing products or duplicates in your results.

The Solution: Server-Side Pagination

The key to successful pagination lies in using server-side limits and offsets:

$page = 1; // Current page number
$limit = 500; // Number of records per page

$filters = new Varien_Simplexml_Element('<filters/>');
$products = $proxy->call($sessionId, 'catalog_product.list', array(
    'filter' => $filters,
    'page_size' => $limit,
    'page' => $page
));

By setting the page_size and page parameters in your SOAP call, you can control how many records are returned per page. This allows you to paginate through your product list without exceeding memory limits.

Best Practices for Efficient Pagination

  1. Keep your page size reasonable (500-1000) to minimize API calls.
  2. Use server-side pagination as it’s more efficient than client-side pagination.
  3. If performance is an issue, consider indexing and optimizing your database.
  4. Always catch and handle errors gracefully.

Conclusion

Pagination in Magento SOAP API requires a strategic approach that leverages server-side limits and offsets effectively. By avoiding memory-intensive operations and utilizing the built-in pagination features of the API, you can retrieve product data efficiently without exhausting resources.

Remember to always optimize your database for better performance and consider using indexing to speed up filter execution.

For more in-depth guides on Magento development and best practices, be sure to check out our Magento Development Resources at Laravel Company.

Catalog API Errors

Our network