Created
December 11, 2017 08:11
-
-
Save MageryThemes/abb1a68484a4d294e23d06a54ed7bc93 to your computer and use it in GitHub Desktop.
How to get customer details in Magento 2 using SOAP API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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