2

I'm trying to list all products via the REST API. I have 1195 products in my store, but the API is consistently only returning 849 of them, and it's the same ones that are left out every time.

My requests look like this:

https://mystore.com/rest/V1/products?searchCriteria[pageSize]=100&searchCriteria[currentPage]=1`

(Repeated for all subsequent pages, of course.)

I have tried specifying lists of SKUS and using a filter group with the in operator, rather than just leaving it unspecified, but the same products are still missing from the result.

However, if I query for the missing products individually (i.e. /rest/V1/products/123) it works no problem.

I've looked over the products that are being left out to try and determine whether there's some feature common to them that might be causing them to be left out, but I can't find anything. Some are enabled and some are disabled, some are in stock and some are out of stock, they're attached to various different categories, etc.

Has anybody else ever run into an issue like this? I'm on Magento 2.3.6, for reference.

2
  • It looks like there is a condition in productRepository getList that do an inner join on status ans visibility. Is it possible that some of your products do not have any value for visibility or status? function getList in vendor/magento/module-catalog/Model/ProductRepository.php Jun 14, 2021 at 19:19
  • @CarloRicci sadly this doesn't seem to be the case, I have 1196 rows in catalog_product_entity_int for visibility and 1195 for status, and all are referencing distinct products. Jun 14, 2021 at 21:55

2 Answers 2

1

Magento uses MySQL and whenever doing the pagination query, we need to include the sort order field, otherwise, an inconsistent result will be returned.

So if you try to include the sort order field as below and retest, you will get the missing products.

https://mystore.com/rest/V1/products?searchCriteria[pageSize]=100&searchCriteria[currentPage]=1&searchCriteria[sortOrders][0][field]=entity_id&searchCriteria[sortOrders][0][direction]=asc

Reference docs:

0

have you managed to solve this? I have the same problem in Magento 2.4.4.

1
  • I never solved it. I wound up just pulling a list of products from the database directly. For what it's worth, however much it may offend purists, I highly recommend hitting the database directly if your needs are simple enough to make it practical. It's much, much faster than trying to go through the API. Nov 18, 2022 at 21:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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