Skip to content

How to add custom sort like Most View and Best Selling products in API of Product List in Magento 2?

How do we add custom sorts like Most View and Best Selling products in the API of Product List in Magento 2?

I need to add the most views and best-selling products in /V1/products to this API using search criteria.

eg: http://domain.com/index.php/rest/V1/products?searchCriteria[page_size]=10&searchCriteria[sortOrders][0][field]=most-view&searchCriteria[sortOrders][0][direction]=ASC

any help on this?