3

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
asked Oct 12, 2016 at 11:04
2
  • Check magento.stackexchange.com/questions/154198/… Commented 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.. Commented Jan 19, 2017 at 9:56

1 Answer 1

2

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

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.