cancel
Showing results for 
Search instead for 
Did you mean: 

how can i fetch order details through rest api in magento 2

SOLVED

how can i fetch order details through rest api in magento 2

hi guys , I just want to fetch order details through rest api in magento 2 ? is this possible ?

if possible ! plz guide me .

1 ACCEPTED SOLUTION

Accepted Solutions

Re: how can i fetch order details through rest api in magento 2

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 !

if issue solved,Click Kudos & Accept as Solution

View solution in original post

7 REPLIES 7

Re: how can i fetch order details through rest api in magento 2

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

If Issue Solved, Click Kudos/Accept As solutions. Get Magento insight from
Magento 2 Blogs/Tutorial

Re: how can i fetch order details through rest api in magento 2

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 !

if issue solved,Click Kudos & Accept as Solution

Re: how can i fetch order details through rest api in magento 2

How can I get all the orders ?

Re: how can i fetch order details through rest api in magento 2

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 !

if issue solved,Click Kudos & Accept as Solution

Re: how can i fetch order details through rest api in magento 2

getting the below error :

 

Array ( [message] => Invalid type for value: "searchCriteria[filter_groups][0][filters][0][field]=1". Expected Type: "int". )

Re: how can i fetch order details through rest api in magento 2

 

 

 

Re: how can i fetch order details through rest api in magento 2

its not working ?