magentomagento2magento-rest-api

How to filter by category in Magento 2's API?


In Magento 2's REST API, there is an option to search a product using various search criteria. As you know, an example is given below:

http://magentohost/rest/V1/products?searchCriteria[filter_groups][0][filters][0][field]=name& searchCriteria[filter_groups][0][filters][0][value]=%macbook%& searchCriteria[filter_groups][0][filters][0][condition_type]=like

But I have not found an option to search by category.

How can we do that?


Solution

  • To search by category, it is simple. You have to just pass category_id as a field. Have a look at below example:

    http://magentohost/rest/V1/products?searchCriteria[filterGroups][0][filters][0][field]=category_id& searchCriteria[filterGroups][0][filters][0][value]=4& searchCriteria[filterGroups][0][filters][0][conditionType]=eq&searchCriteria[sortOrders][0][field]=created_at& searchCriteria[sortOrders][0][direction]=DESC& searchCriteria[pageSize]=10& searchCriteria[currentPage]=1