Magento – Magento 2 rest api get all products of a parent category

apicategory-productsmagento2rest

I want to get the products of a given category id.

http://magentohost.com/rest/V1/faya-capbargainapi/product-list?searchCriteria[filter_groups][0][filters][0][field]=category_id& searchCriteria[filter_groups][0][filters][0][value]=33& searchCriteria[filter_groups][0][filters][0][condition_type]=eq&searchCriteria[pageSize]=10

The above rest api call will return all the products for category id 33.
The category 33 is a child of category id 30. Category 30 has another two childs. My requirement is to get all products under the category id 30.

I tried for http://magentohost.com/rest/V1/faya-capbargainapi/product-list?searchCriteria[filter_groups][0][filters][0][field]=category_id& searchCriteria[filter_groups][0][filters][0][value]=30& searchCriteria[filter_groups][0][filters][0][condition_type]=eq&searchCriteria[pageSize]=10

But it returns no products. I tried to change the "eq" keyword to 'in', 'finset' etc. But nothing works.

Best Answer

To achieve it you need to add products to the parent category too for attribute  Categories on product edit page or new page.
Check under category 30 this products are there or not under products in category.
If you have products there than only you will get expected result.
Related Topic