1

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?

asked Jun 28, 2019 at 10:02
1

1 Answer 1

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.

answered Jun 28, 2019 at 11:18

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.