cancel
Showing results for 
Search instead for 
Did you mean: 

REST API: How to combine filters using OR in SearchCriteria?

   Did you know you can see the translated content as per your choice?

Translation is in progress. Please check again after few minutes.

REST API: How to combine filters using OR in SearchCriteria?

I tried both filters and filter groups, all translated into "AND".

Below, I intentionally used an invalid attribute to see the SQL generated.

 

1. Tried using 2 filters of same group

http://magento-dev:2080/rest/V1/orders?searchCriteria[filter_groups][customer_sales_order][filters][0][condition_type]=eq&searchCriteria[filter_groups][customer_sales_order][filters][0][field]=customer_id&searchCriteria[filter_groups][customer_sales_order][filters][0][value]=3&searchCriteria[filter_groups][customer_sales_order][filters][1][condition_type]=eq&searchCriteria[filter_groups][customer_sales_order][filters][1][field]=sku&searchCriteria[filter_groups][customer_sales_order][filters][1][value]=T760&searchCriteria[page_size]=10

 

  Response body   {"message":"SQLSTATE[42S22]: Column not found: 1054 Unknown column 'sku' in 'where clause', query was: SELECT `main_table`.* FROM `sales_order` AS `main_table` WHERE (`main_table`.`customer_id` = '3') AND (`sku` = 'T760') LIMIT 10"

 

2. tried using 2 filter_groups

 http://magento-dev:2080/rest/V1/orders?searchCriteria[filter_groups][customer_sales_order][filters][0][condition_type]=eq&searchCriteria[filter_groups][customer_sales_order][filters][0][field]=customer_id&searchCriteria[filter_groups][customer_sales_order][filters][0][value]=4&searchCriteria[filter_groups][key_ring_sales][filters][0][condition_type]=eq&searchCriteria[filter_groups][key_ring_sales][filters][0][field]=sku&searchCriteria[filter_groups][key_ring_sales][filters][0][value]=T760

 

  Response body   {"message":"SQLSTATE[42S22]: Column not found: 1054 Unknown column 'sku' in 'where clause', query was: SELECT `main_table`.* FROM `sales_order` AS `main_table` WHERE (`main_table`.`customer_id` = '4') AND (`sku` = 'T760')"