Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 354
Jinu Joseph Daniel Avatar asked Feb 09 '17 20:02

Jinu Joseph Daniel


1 Answers

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
like image 64
Altaf Hussain Avatar answered Sep 29 '22 17:09

Altaf Hussain