5

I'm trying to use the Get Orders API with searchCriteria to filter Orders with base_subtotal range between two values. But I have only been able to use the lt and gt. I'm unable to use both in the same query.

I can see the Magento documentation mentioning that I can do that using the from and to operators. However, I can't figure out how to get it to work or what is its syntax.

The current request I'm using to get the Orders with base_subtotal less than 50:

http://{magento_host}/magento/rest/default/V1/orders?searchCriteria[filter_groups][0][filters][0][field]=base_subtotal&searchCriteria[filter_groups][0][filters][0][value]=50&searchCriteria[filter_groups][0][filters][0][condition_type]=lt

What I'm trying to do is getting the orders where base_subtotal < 50 AND base_subtotal > 20.

Any idea how to do this using searchCriteria?

2

Here is how to do it, you can to modify your request in two different ways in my opinion:

Using less than and greather than

http://{magento_host}/magento/rest/default/V1/orders?
searchCriteria[filter_groups][0][filters][0][field]=base_subtotal&
searchCriteria[filter_groups][0][filters][0][value]=50&
searchCriteria[filter_groups][0][filters][0][condition_type]=lt&
searchCriteria[filter_groups][0][filters][1][field]=base_subtotal&
searchCriteria[filter_groups][0][filters][1][value]=20&
searchCriteria[filter_groups][0][filters][1][condition_type]=gt

Using from and to

I'm not entirely sure from/to can be used for normal value range or if it can only be used with dates. Anyway here's how it would be done with from/to

http://{magento_host}/magento/rest/default/V1/orders?
searchCriteria[filter_groups][0][filters][0][field]=base_subtotal&
searchCriteria[filter_groups][0][filters][0][value]=20&
searchCriteria[filter_groups][0][filters][0][condition_type]=from&
searchCriteria[filter_groups][0][filters][1][field]=base_subtotal&
searchCriteria[filter_groups][0][filters][1][value]=50&
searchCriteria[filter_groups][0][filters][1][condition_type]=to

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.