1

I am trying to get the sales orders from magento2 REST API. I am using the below query to get the complete orders within entity_id range:

$ch = curl_init( Helper::getURL() . "orders?searchCriteria[filter_groups][0][filters][0][field]=status" .
         "&searchCriteria[filter_groups][0][filters][0][value]=" . $status .
         "&searchCriteria[filter_groups][0][filters][0][condition_type]=like" .
         "&searchCriteria[filter_groups][0][filters][0][field]=entity_id" .
         "&searchCriteria[filter_groups][0][filters][0][value]=" . $idMin .
         "&searchCriteria[filter_groups][0][filters][0][condition_type]=gteq" .
         "&searchCriteria[filter_groups][0][filters][0][field]=entity_id" .
         "&searchCriteria[filter_groups][0][filters][0][value]=" . $idMax .
         "&searchCriteria[filter_groups][0][filters][0][condition_type]=lteq" .
         "&searchCriteria[pageSize]=500&fields=items[entity_id,customer_email,customer_firstname,customer_lastname,customer_is_guest," .
         "increment_id,status,created_at,subtotal,total_paid,total_due,grand_total,shipping_amount,payment[method,amount_paid]," .
         "billing_address[city,email,firstname,lastname,postcode,street,telephone,company,region],items[item_id,name,original_price,price," .
         "product_id,qty_canceled,qty_invoiced,qty_ordered,qty_refunded,qty_returned,qty_shipped,row_total,sku,discount_amount]]" );

Status filter and idMin filter are not working. Only idMax filer is working. The search returns all sales orders having entity_id less than idMax with different status and entity_id starting from zero.

What is the problem with the search criteria?

0

Problem Solved. The issue is related to filter index. Each filter must have different index:

$ch = curl_init( Helper::getURL() . "orders?searchCriteria[filter_groups][0][filters][0][field]=status" .
     "&searchCriteria[filter_groups][0][filters][0][value]=" . $status .
     "&searchCriteria[filter_groups][0][filters][0][condition_type]=like" .
     "&searchCriteria[filter_groups][0][filters][1][field]=entity_id" .
     "&searchCriteria[filter_groups][0][filters][1][value]=" . $idMin .
     "&searchCriteria[filter_groups][0][filters][1][condition_type]=gteq" .
     "&searchCriteria[filter_groups][0][filters][2][field]=entity_id" .
     "&searchCriteria[filter_groups][0][filters][2][value]=" . $idMax .
     "&searchCriteria[filter_groups][0][filters][2][condition_type]=lteq" .
     "&searchCriteria[pageSize]=500&fields=items[entity_id,customer_email,customer_firstname,customer_lastname,customer_is_guest," .
     "increment_id,status,created_at,subtotal,total_paid,total_due,grand_total,shipping_amount,payment[method,amount_paid]," .
     "billing_address[city,email,firstname,lastname,postcode,street,telephone,company,region],items[item_id,name,original_price,price," .
     "product_id,qty_canceled,qty_invoiced,qty_ordered,qty_refunded,qty_returned,qty_shipped,row_total,sku,discount_amount]]" );

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.