If I login as an admin user, how can I get details of customer and orders list with payment details using REST API in Magento2
diazwatson
2,4782 gold badges28 silver badges39 bronze badges
-
Check magento.stackexchange.com/questions/154198/…Sohel Rana– Sohel Rana2017年01月19日 09:21:41 +00:00Commented Jan 19, 2017 at 9:21
-
i was put this code for get all data of customers $request->setUri('localhost/magento2/rest/V1/customers'); $request->setMethod(\Zend\Http\Request::METHOD_POST); and got the below error when i print the response. stdClass Object ( [message] => %fieldName is a required field. [parameters] => stdClass Object ( [fieldName] => customer ) ) can you please suggest me how can i resolve the issue..Kartik Asodariya– Kartik Asodariya2017年01月19日 09:56:41 +00:00Commented Jan 19, 2017 at 9:56
1 Answer 1
Below is the script for order api.
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
require ('/vendor/autoload.php');
require('/vendor/zendframework/zend-http/src/Headers.php');
require('/vendor/zendframework/zend-http/src/Request.php');
require('/vendor/zendframework/zend-http/src/Response.php');
/*Token Generated from SYstem Integratio*/
$token = '9kvn45tbopelidqj9ddita9rvyujk1tl';
$httpHeaders = new \Zend\Http\Headers();
$httpHeaders->addHeaders([
'Authorization' => 'Bearer ' . $token,
'Accept' => 'application/json',
'Content-Type' => 'application/json'
]);
$request = new \Zend\Http\Request();
$request->setHeaders($httpHeaders);
$request->setUri('http://1270.0.1/magentoce27/index.php/rest/V1/orders/1');
$request->setMethod(\Zend\Http\Request::METHOD_GET);
$client = new \Zend\Http\Client();
$options = [
'adapter' => 'Zend\Http\Client\Adapter\Curl',
'curloptions' => [CURLOPT_FOLLOWLOCATION => true],
'maxredirects' => 0,
'timeout' => 30
];
$client->setOptions($options);
$response = $client->send($request);
echo "<pre>".print_r(json_decode($response->getBody()),true)."</pre>";
?>
Here, is the script for customer api,
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
require ('/vendor/autoload.php');
require('/vendor/zendframework/zend-http/src/Headers.php');
require('/vendor/zendframework/zend-http/src/Request.php');
require('/vendor/zendframework/zend-http/src/Response.php');
/*Token Generated from SYstem Integratio*/
$token = '9kvn45tbopelidqj9ddita9rvyujk1tl';
$httpHeaders = new \Zend\Http\Headers();
$httpHeaders->addHeaders([
'Authorization' => 'Bearer ' . $token,
'Accept' => 'application/json',
'Content-Type' => 'application/json'
]);
$request = new \Zend\Http\Request();
$request->setHeaders($httpHeaders);
$request->setUri('http://1270.0.1/magentoce27/index.php/rest/V1/customers/1');
$request->setMethod(\Zend\Http\Request::METHOD_GET);
$client = new \Zend\Http\Client();
$options = [
'adapter' => 'Zend\Http\Client\Adapter\Curl',
'curloptions' => [CURLOPT_FOLLOWLOCATION => true],
'maxredirects' => 0,
'timeout' => 30
];
$client->setOptions($options);
$response = $client->send($request);
echo "<pre>".print_r(json_decode($response->getBody()),true)."</pre>";
?>
Kindly note that you might need to do changes in API as per your requirement.
Also you will need to generate token from admin panel and put that token into script and also change url as per your project setup.
answered Oct 12, 2016 at 11:46
Rushvi
2,8532 gold badges15 silver badges31 bronze badges
default