magentomagento2magento-rest-api

Magento Rest API - multiple product list in one call


I want to access specified multiple product list in one call. for example access all the products in category id 14 and 15.

This provide the product list id 14:

/V1/products?searchCriteria[filter_groups][0][filters][0][field]=category_id&searchCriteria[filter_groups][0][filters][0][value]=14

This provide the product list id 15:

/V1/products?searchCriteria[filter_groups][0][filters][0][field]=category_id&searchCriteria[filter_groups][0][filters][0][value]=15

But if I want to get both in one call: is possible to make somenthing like this ?:

/V1/products?searchCriteria[filter_groups][0][filters][0][field]=category_id&searchCriteria[filter_groups][0][filters][0][value]=14,15

Any help?


Solution

  • You can use the in condition type

    GET <host>/rest/<store_code>/V1/products?
    searchCriteria[filter_groups][0][filters][0][field]=entity_id&
    searchCriteria[filter_groups][0][filters][0][value]=1,2,3,4,5&
    searchCriteria[filter_groups][0][filters][0][condition_type]=in
    

    This example can be extended to work with category etc as you require, see examples

    https://devdocs.magento.com/guides/v2.4/rest/performing-searches.html