I need to fetch the first n order with status processing or any other.
Does anyone know the API string?
For Get Order Collection using REST API with status processing, You can pass below request url to fetch order data from Magento.
https://yourhost.com/index.php/rest/V1/orders/?searchCriteria[filterGroups][0][filters][0][field]=status&searchCriteria[filterGroups][0][filters][0][value]=processing&searchCriteria[filterGroups][0][filters][0][conditionType]=eq
Method: GET
Authorization Token: Admin Token
OR
My Curl method:
$userData = array("username" => "adminuser", "password" => "adminpassowrd");
$ch = curl_init("https://yourhost.com/index.php/rest/V1/integration/admin/token");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($userData));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json", "Content-Lenght: " . strlen(json_encode($userData))));
$token = curl_exec($ch);
$apiOrderUrl = 'https://yourhost.com/index.php/rest/V1/orders/?searchCriteria[filterGroups][0][filters][0][field]=status&searchCriteria[filterGroups][0][filters][0][value]=processing&searchCriteria[filterGroups][0][filters][0][conditionType]=eq';
$ch = curl_init($apiOrderUrl);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json", "Authorization: Bearer " . json_decode($token)));
$result = curl_exec($ch);
$results = json_decode($result, true); // all orders with status pending
foreach ($results['items'] as $order) {
$commentData = array(
'id' => $order['entity_id'], //order_id
'statusHistory' => array(
'comment' => 'Received order?',
'entity_id' => null,
'is_customer_notified' => '1',
'created_at' => now(),
'parent_id' => $order['entity_id'], //order_id
'entity_name' => 'order',
'status' => 'processing', //assign new status to order
'is_visible_on_front' => '1'
)
);
$commentData = json_encode($commentData,true);
$orderStatusApiUrl = 'https://yourhost.com/index.php/rest/V1/orders/'.$order['entity_id'].'/comments';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$orderStatusApiUrl);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $commentData );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json", "Authorization: Bearer " . json_decode($token)));
$response = curl_exec($ch); //true
}
I got the string as below. I have used searchCriteria[pageSize] and searchCriteria[currentPage] to fetch first n order and also can fetch page wise order.
$pageSize = 100; // magento will create order table with 100 orders in a page
$currentPage = 1; // first page
$ch = curl_init("https://yourhost.com/index.php/rest/V1/orders?searchCriteria[filter_groups][0][filters][0][field]=status&searchCriteria[filter_groups][0][filters][0][value]=processing&searchCriteria[filter_groups][0][filters][0][conditionType]=eq&searchCriteria[pageSize]={$pageSize}&searchCriteria[currentPage]={$currentPage}&fields=items[increment_id,status,base_tax_amount,grand_total,base_subtotal,items,billing_address,payment,created_at]");
I have added a fields parameter by which I can fetch the minimum data of order.