hi guys , I just want to fetch order details through rest api in magento 2 ? is this possible ?
if possible ! plz guide me .
Solved! Go to Solution.
Hi @bharath553
Yes it is possible to get order details using REST API.
Below is the code :
$userData = array("username" => "admin", "password" => "admin123"); $ch = curl_init("http://magento213/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); $ch = curl_init("http://magento213/index.php/rest/V1/orders/1"); 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); $result = json_decode($result, 1); echo '<pre>';print_r($result);
Fore more details refer this link - https://magento.stackexchange.com/questions/154198/magento-2-how-to-get-order-information-using-rest...
Hope it helps !
You need to access swagger for Magento 2 API,
Go to http://devdocs.magento.com/swagger/
salesOrderRepositoryV1
Action : GET
Request URL: {SITE_URL}/V1/orders/{id}
Now replace {id} with order id to get specific order data
Hi @bharath553
Yes it is possible to get order details using REST API.
Below is the code :
$userData = array("username" => "admin", "password" => "admin123"); $ch = curl_init("http://magento213/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); $ch = curl_init("http://magento213/index.php/rest/V1/orders/1"); 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); $result = json_decode($result, 1); echo '<pre>';print_r($result);
Fore more details refer this link - https://magento.stackexchange.com/questions/154198/magento-2-how-to-get-order-information-using-rest...
Hope it helps !
Hi @bharath553
For all order i would suggest you to refer this link - https://magento.stackexchange.com/questions/155295/magento2-get-all-orders-using-rest-api
You actually required to use SearchCriteria where you need to pass at least one criteria to get the order details !
Hope it helps !
getting the below error :
Array ( [message] => Invalid type for value: "searchCriteria[filter_groups][0][filters][0][field]=1". Expected Type: "int". )
its not working ?