Skip to content

Instantly share code, notes, and snippets.

@MageryThemes
Created December 11, 2017 08:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MageryThemes/abb1a68484a4d294e23d06a54ed7bc93 to your computer and use it in GitHub Desktop.
Save MageryThemes/abb1a68484a4d294e23d06a54ed7bc93 to your computer and use it in GitHub Desktop.
How to get customer details in Magento 2 using SOAP API
<?php
$baseUrl = '<YOUR_DOMAIN>/';
$request = new SoapClient(
"{$baseUrl}soap/?wsdl&services=integrationAdminTokenServiceV1",
['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(
"{$baseUrl}soap/default?wsdl&services=customerCustomerRepositoryV1",
['version' => SOAP_1_2, 'stream_context' => $context]
);
$result = $soapClient->customerCustomerRepositoryV1GetById(['customerId' => 126]);
var_dump($result);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment