Skip to main content
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user

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'))".

"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": [ {

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"

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 I apply filter on "product_id"

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"

Source Link
SharmaV
  • 129
  • 14

Filter orders using Product Id in Magento 2 Order rest API

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 I apply filter on "product_id"