How to get customer orders on the base of customer token in magento 2?Please help me.Thanks in Advance
2 Answers
Url: http://192.168.1.74/B2B/Magento/index.php/rest/V1/orders?searchCriteria[pageSize]=25&searchCriteria[currentPage]=1&searchCriteria[filterGroups][0][filters][0][value]=128&searchCriteria[filterGroups][0][filters][0][field]=customer_id&searchCriteria[filterGroups][0][filters][0][conditionType]=eq
method : GET
Headers
Authorization :: Bearer <Admintokenvalue>
-
-
It will be not possible using that service as it need admin token according to ACL.xml. so write anonymous service using the same logic Commented May 29, 2018 at 9:05
First you need to get accesstoken of admin and then needs to call order api with passing that AccessToken.
Code for get admin accesstoken :
$userData = array("username" => "admin", "password" => "admin123");
$ch = curl_init("http://yourwebsiteurl/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);
Get order details :
$ch = curl_init("http://yourwebsiteurl/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);
-
-
Can, try this code : domain.com/index.php/rest/V1/orders?searchCriteria[filter_groups][0][filters][0][field]=customer_email&searchCriteria[filter_groups][0][filters][0][value][email protected]&searchCriteria[filter_groups][0][filters][0][condition_type]=eq&searchCriteria[filter_groups][1][filters][0][field]=status&searchCriteria[filter_groups][1][filters][0][value]=pending&searchCriteria[filter_groups][1][filters][0][condition_type]=eq Commented May 29, 2018 at 5:32
-
it show "message":"Consumer is not authorized to access %resources","parameters":{"resources":"Magento_Sales::sales". Commented May 29, 2018 at 5:37
-
-
Yes, i will change,but showing same response Consumer is not authorized. Commented May 29, 2018 at 5:52