I am trying to fetch customer detail with magento 2 API. but I didn't get solution for that.


After looking at the M2 documentation here, you will see how to connect and use the Magento 2 API.

From there, all you have to do is look at what you want to do from within the module itself. The API calls for Customers are in app/code/Magento/Customer/etc/webapi.xml.

To get customer details for example, the endpoint is:


From there, you can fetch your customer information.

Also take a look at app/code/Magento/Customer/Api/ to get an idea of what API functionality is available to you. You can manage their account, search customers, customer group management, address, and more.

Here is an example of how to search for customers, taken straight from the documentation above:


$token = 'token';
$httpHeaders = new \Zend\Http\Headers();
   'Authorization' => 'Bearer ' . $token,
   'Accept' => 'application/json',
   'Content-Type' => 'application/json'

Construct Request:

$request = new \Zend\Http\Request();

$params = new \Zend\Stdlib\Parameters([
   'searchCriteria' => '*'

Call Endpoint

$client = new \Zend\Http\Client();
$options = [
   'adapter'   => 'Zend\Http\Client\Adapter\Curl',
   'curloptions' => [CURLOPT_FOLLOWLOCATION => true],
   'maxredirects' => 0,
   'timeout' => 30

$response = $client->send($request);

The $response is in JSON.

Now that you know how to pull customers via the search, you can also do other commands listed in the webapi.xml document mentioned above.

| improve this answer | |
  • can you please tell me how can I do same process with soap ? – Troubleshooter Jan 27 '16 at 19:04

I have not the full answer and code for that but I can suggest you to take a look at Magento documentation for API : http://devdocs.magento.com/guides/v2.0/get-started/bk-get-started-api.html
Here you can find generic examples and some explanation on how to use APIs

Here you can find some source to be familiar with Magento 2 APIs and how to use them :
- https://firebearstudio.com/blog/magento-2-api.html
- http://devdocs.magento.com/guides/v2.0/rest/bk-rest.html
- http://devdocs.magento.com/guides/v2.0/rest/rest_endpoints.html (customer part)
- http://devdocs.magento.com/guides/v2.0/rest/list.html (customer part)
- http://alankent.me/2015/07/24/creating-a-new-rest-web-service-in-magento-2/

| improve this answer | |
  • on mage document there is no example of such example. – Troubleshooter Jan 27 '16 at 17:07
  • You have in Usage notes for example. Are you familiar with using APIs in a general way or are you searching for examples of this too ? – Matthéo Geoffray Jan 27 '16 at 17:09
  • I udpate my answer to give you some links that may helps you ;) – Matthéo Geoffray Jan 27 '16 at 17:16

$token = '6ge34qaj7ugklona2in8fmmig93qmblx';
$wsdlUrl = 'http://localhost/magento214/soap/default?wsdl&services=customerAccountManagementV1';
$opts = ['http'=> ['header' => "Authorization: Bearer " .$token]];
$context = stream_context_create($opts);
$soapClient  = new \Zend\Soap\Client($wsdlUrl);
$slide = array("customerId" => 1);
$result = $soapClient->customerAccountManagementV1GetDefaultShippingAddress(array("customerId" => 1));
$result1 = $soapClient->customerAccountManagementV1GetDefaultBillingAddress(array("customerId" => 1));
echo "\n";
| improve this answer | |

If you want to do this using SOAP you should use customerCustomerRepositoryV1 web service. It has method named customerCustomerRepositoryV1GetById.
Take a look at the following example:

$baseUrl = '<YOUR_DOMAIN>/';
$request = new SoapClient(
    ['soap_version' => SOAP_1_2]

// Get authorization token
$token = $request->integrationAdminTokenServiceV1CreateAdminAccessToken([
    'username' => '<YOUR_ADMIN_USER>',
    'password' => '<YOUR_PASSWORD>'

// Create authorization header
$opts = [
    'http' => [
        'header' => 'Authorization: Bearer ' . $token->result
$context = stream_context_create($opts);

// Init SOAP client
$soapClient = new SoapClient(
    ['version' => SOAP_1_2, 'stream_context' => $context]

$result = $soapClient->customerCustomerRepositoryV1GetById(['customerId' => 126]);

| improve this answer | |

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.