Magento – Magento 2 API: Filter orders by extension attribute

attributesmagento2orderssearch-criteria

I have an extension with an attribute assigned to order items called warehouse.
I can see this attribute under the property "extension_attributes".
I need to filter orders based on this attribute. I can't find any documentation on how to do this.

Example API response snippet:

[items] => Array(
    [0] => Array(
        [extension_attributes] => Array(
            [warehouse] => MyWarehouse
        )
    )
)

The following filter generates an internal error:

searchCriteria[filter_groups][2][filters][0][field]=warehouse,searchCriteria[filter_groups][2][filters][0][value]=mywarehouse,searchCriteria[filter_groups][2][filters][0][condition_type]=eq

Any suggestions on how I can filter orders using the warehouse attribute via the API?

– Additional point on this question:

In this case, if we will follow Fooman blog.Then can we filter the collection by the extension* attribute?

  • Collection filter by this extension Attribute Should be run Fast?
  • If we use custom db table for save this extension attribute table then how can filter?
    Should it work magento frontend and backend also.
  • where in need do modification and which class need to add or any reference blog ?

Wait for good and describe/brief answer on this points?

Best Answer

You can try this

/rest/V1/orders?searchCriteria[filter_groups][0][filters][0][field]=warehouse&searchCriteria[filter_groups][0][filters][0][value]=MyWarehouse&searchCriteria[filter_groups][0][filters][0][condition_type]=eq
Related Topic