0

I am using this API "http://localhost/test/rest/V1/orders?searchCriteria[filter_groups][0][filters][0][field]=product_id&searchCriteria[filter_groups][0][filters][0][value]=24" to filter orders by product id.

But getting this message

"SQLSTATE[42S22]: Column not found: 1054 Unknown column 'product_id' in 'where clause', query was: SELECT main_table.* FROM sales_order AS main_table WHERE ((product_id = '24'))".

If I am using filter on entity_id then it is working fine.I found in response that both of the fields stored at different positions.

eg. {
    "items": [
        {
            "entity_id": 1,
            "items": [
                {

                    "product_id": 14,
                }
            ]
        }
    ]
}

That's why API is not accepting "product_id" filter. So how can a I apply filter on "product_id"

1
  • a order itself doesn't have a productId. the productId is stored in the order-item Commented Jul 24, 2019 at 12:43

1 Answer 1

0

Magneto 2 does not allow to filter Orders by product's IDs so you have to write custom API(code) for it by Joining "sales_order_item" table.

2
  • Does magento have any API by which I can get no. of sold out products(for a particular product)?
    – SharmaV
    Commented Jul 25, 2019 at 2:59
  • 3
    Try this: [domainname.com/rest/V1/orders/…
    – Ankit
    Commented Jul 25, 2019 at 6:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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