Magento API - Get Product Names from specific Category

Magento API - Get Product Names from specific Category

September 5, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento API - Get Product Names from specific Category

Optimizing Magento API for Category Product Retrieval

Hello developers! I saw your query about optimizing product retrieval using the Magento API. You’re on the right track, but there are indeed some performance optimizations we can make to handle larger product catalogs more efficiently.

The Current Approach and Its Limitations

Your current code uses a nested loop approach where you first fetch all products from a category, then iterate through each product ID to retrieve individual product details. While this works, it results in a high number of API calls - one for each product in the category.

For a shop with 1000 products per category, this would mean making up to 1000 API calls just to get basic product details like names and SKUs. This approach is not scalable and will certainly put a strain on your server if you need to fetch data from multiple categories.

Optimizing the Product Retrieval Process

The key optimization lies in reducing the number of API requests made for each category.

Option 1: Fetching Multiple Products at Once

Magento’s SOAP API allows you to retrieve multiple products at once using the catalog_product.getList method. This method accepts a set of filters and returns an array of product arrays, including basic details like name, SKU, price, etc.

Here’s how you can modify your code:

// ...

$filters = [
    'category_ids' => [107],
    'page_size' => 50 // You can adjust this based on your server capacity
];

try {
    $productList = $client->call($sess_id, 'catalog_product.getList', $filters);

    foreach ($productList as $product) {
        echo "Product Name: {$product['name']}\n";
        echo "SKU: {$product['sku']}\n\n";
    }
} catch (Exception $e) {
    // ...
}

// ...

In this version, we fetch up to 50 products at a time using page_size. You can adjust this value depending on your server’s ability to handle the response.

Option 2: Using the GraphQL API

If you have Magento 2.3 or later, consider switching to the GraphQL API for faster responses and better performance.

The GraphQL API allows you to fetch multiple types of data in a single request, reducing network round trips significantly. To get product names from a specific category using the GraphQL API:

  1. Install the GraphQL integration: https://laravelcompany.com/magento-graphql-integration-tutorial

  2. Use the following query:

{
  products(filter: {category_id: {eq: 107}}) {
    items {
      name
      sku
    }
  }
}

This single query fetches all product names and SKUs for category ID 107.

Conclusion

Remember, optimizing API calls is crucial when dealing with large product catalogs in Magento. By fetching multiple products at once or using the GraphQL API, you can significantly reduce the number of requests and improve performance.

Always keep an eye on your server’s load when making bulk API calls. If you find that the current setup still isn’t enough for your traffic, consider implementing caching mechanisms like Redis or Memcached to store frequently accessed data locally.

Happy coding!

Catalog Database Performance API

Our network