I am trying to integrate Magento 2 using SOAP services. I am bit struggling on the initial steps to authenticate to the store.

My objective is to connect to Magento 2 store and get the customer details of the given E-mail address.

I created an Integration point with the proper privileges. I got the 4 secret tokens and passwords as below.

Consumer Key: aaa
Consumer Secret: bbb
Access Token: cccc
Access Token Secret: ddd

How can I first authenticate?


You should use Access Token as a Bearer token:

$opts = ['http' => ['header' => "Authorization: Bearer " . $token]];
$context = stream_context_create($opts);
$soapClient = new \Zend\Soap\Client($wsdlUrl);

More details are in official documentation: http://devdocs.magento.com/guides/v2.0//get-started/gs-web-api-request.html

  • My client is a PHP client and should I use Zend framework as mandatory to create the soapClient? – Malaiselvan Jan 19 '16 at 11:08
  • It is not mandatory to use Zend, just use \SoapClient and specify correct Authorization header during request. – Alex Paliarush Jan 20 '16 at 9:38
  • 1
    @AlexPaliarush I cant able to use the normal PHP SoapClient. If possible can be give me a code snippet???? – Malaiselvan Jan 30 '16 at 19:23
  • I have just wasted hours on a similar problem and I am not sure my php & webserver support the streamcontext. Anyone know what versions etc. this might work in? – iphigenie Nov 25 '16 at 14:01

To answer @Malaiselvan and others which fail in using native PHP 7 SoapClient, there is a bug in the Magento 2 documentation http://devdocs.magento.com/guides/v2.0/get-started/soap/soap-web-api-calls.html which states:

$soapClient = new SoapClient($wsdlUrl, ['version' => SOAP_1_2, 'context' => $context]);

Instead, you should pass 'soap_version' and 'stream_context' parameters, like so:

$soapClient = new SoapClient($wsdlUrl,  ['soap_version' => SOAP_1_2, 'stream_context' => $context]);

This will work:


    $url = 'http://your-magento-url/soap/default?wsdl&services=customerCustomerRepositoryV1';

         $opts = array(
                    'header' => 'Authorization: Bearer 2fvvl0xyd9kkjliqkumsqxj7niev44ncfc'
        $context = stream_context_create($opts);

        $client = new SoapClient($url,  array('soap_version'=>SOAP_1_2, 'stream_context'=>$context));


        $soapResponse = $client->customerCustomerRepositoryV1GetList(array('searchCriteria'=>''));        

}catch(SoapFault $f){
    echo "Fault: ".$f->getMessage();
}catch(Exception $e){
    echo $e->getMessage();
  • 1
    Why will this work? What will it do? "Code only" answers are not very helpful. Please add at least a little explanation. – Fabian Schmengler Apr 5 '16 at 12:59

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.