3

How to GET all orders from magento 2 through Rest API. what is the endpoint url to retrieve all order irrespective of customers.

4

There a good tutorial about Magento 2 API Here

On the basis of above tutorial you can get all order by:

<?php
ini_set('error_reporting', E_ALL);
ini_set("display_errors", "1");

$userData = array("username" => "Admin_username", "password" => "Admin_password");
$ch = curl_init("http://127.0.0.1/mago/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))));

echo $token = curl_exec($ch);

$ch = curl_init("http://127.0.0.1/mago/index.php/rest/V1/orders?searchCriteria=all");
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);

var_dump($result);

Note: searchCriteria=all and searchCriteria=0 both are giving same results

  • thanks Pawan... I have one more doubt. when I try to use filter in products query I'm getting invalid signature in response. without filter I get success response. – SalesforceElearner Sep 11 '18 at 17:50
  • are you asking about magento.stackexchange.com/questions/241052 ? I will update answer to that question soon – Pawan Sep 11 '18 at 17:53
  • If above answer helped/worked, You can accept and upvote it :) – Pawan Sep 11 '18 at 17:54
  • yes pawan. in postman its working. when it comes salesforce apex controller rest api call out... it gives me error.... magento.stackexchange.com/questions/241052 – SalesforceElearner Sep 11 '18 at 17:57
  • I am checking other question. – Pawan Sep 11 '18 at 18:05

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.