I try to fetch all products in bunches from the REST API in Magento 2.3.1:
GET http://example.local/rest/V1/products?searchCriteria[page_size]=100&searchCriteria[sortOrders][0][field]=updated_at&searchCriteria[sortOrders][0][direction]=ASC&searchCriteria[currentPage]=88000
Content-Type: application/json
Authorization: Bearer mybearer
I have 250 Products in the shop, still this request returns results. Shouldn't such a ridiculously high page number return an error or no results?
-
github.com/magento/magento2/issues/8099Alex– Alex2019年06月28日 10:06:33 +00:00Commented Jun 28, 2019 at 10:06
1 Answer 1
I my logic I was assuming, that Magento returns empty results in case the page is invalid / empty, so my script was fetching until $result['items'] is empty.
This is not the case.
So I changed my client like this:
if ($result['total_count'] < $result['search_criteria']['page_size'] * ($result['search_criteria']['current_page'] - 1)) {
return null;
}
and bail out if null is returned.