Every time I run this script. I get an error. I placed this file in the root directory of my magento.




ini_set('display_errors', 1);


$wsdlurl = 'https://www.chemcopharmacy.com/soap/default?wsdl&services=salesOrderRepositoryV1';

$token = 'u46losnl6ia01ctmxxxxxxxxxxxxx'; //access token

$opts = ['http' => ['header' => "Authorization: Bearer ".$token]]; 
$context = stream_context_create($opts); //$arguments = $serviceArgs = 
$serviceArgs = array('searchCriteria'=> 
    array('filterGroups' => 
        array ('filters' =>
            array('field' =>'increment_id',
                  'value' => '000000002' , 
                  'condition_type' => 'eq')
     ) ); 
 $soapClient = new \Zend\Soap\Client($wsdlurl);
 $result = $soapClient->salesOrderRepositoryV1GetList($serviceArgs);

//array('searchCriteria' => $serviceArgs)); //$result = $soapClient->customerCustomerRepositoryV1GetById(array('customerId' => 1));


Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing 
WSDL: Couldn't load from 'https://www.chemcopharmacy.com/soap/default? 
wsdl&services=salesOrderRepositoryV1' : failed to load external entity 
wsdl&services=salesOrderRepositoryV1" in 
soap/src/Client/Common.php:33 Stack trace: #0 
soap/src/Client/Common.php(33): SoapClient- 
>SoapClient('https://www.che...', Array) #1 
soap/src/Client.php(1070): Zend\Soap\Client\Common->__construct(Array, 
'https://www.che...', Array) #2 
soap/src/Client.php(1245): Zend\Soap\Client->initSoapClientObject() #3 
soap/src/Client.php(1156): Zend\Soap\Client->getSoapClient() #4 
/var/www/html/chemcopharmacy/soapexample2.php(29): Zend\Soap\Client- 
>__call('salesOrderRepos. in 
soap/src/Client/Common.php on line 33

What I have done?

  • I have edited the /etc/hosts file and added the MY.IP.ADDRESS DOMAIN.COM

  • I have also set necessary setting in php.ini files for soap like

    extension=php_soap.dll; extension=php_openssl.dll;

2 Answers 2


I tried the SOAP Web Services on my local host and it was working fine. The reason why the Magento 2 was not able to give a response to the request was because it was not able to verify SSL Certificates enabled on the site.

The way I resolved it was to allow self signed SSL verification:

$opts = [
    'http' =>
         'header' => "Authorization: Bearer ".$token
'ssl' => [
    'allow_self_signed' => true , 
    'verify_peer' => false, 
    'verify_peer_name' => false]
$context = stream_context_create($opts);

I hope it helps. ;)


This helped me to fix the failed to load external entity issue https://community.magento.com/t5/Magento-2-x-Technical-Issues/SOAP-Error-Failed-to-load-external-entity/m-p/38906#M917

Adding my snippet

$wsdl = 'http://m2.local.com/soap/?wsdl&services=integrationAdminTokenServiceV1';
    $client = $this->soapClient->create($wsdl, array("soap_version" => SOAP_1_2));

    $token = $client->integrationAdminTokenServiceV1CreateAdminAccessToken(array("username"=>"test", "password"=>"test"));

    $opts = [
        'ssl' => [
        'http' => [
            'header' => 'Authorization: Bearer '. $token->result

    $params = [
        'stream_context' => stream_context_create($opts),
        'cache_wsdl' => WSDL_CACHE_NONE

    $wsdlUrl = 'http://m2.local.com/soap/default?wsdl&services=quoteCartRepositoryV1';
    $soapClient = $this->soapClient->create($wsdlUrl, $params);

    $soapResponse = $soapClient->__getFunctions();

Where the SoapClient is Magento\Framework\Webapi\Soap\ClientFactory

  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review
    – Jarnail S
    Commented Aug 18, 2019 at 14:30
  • hi Jai Edited my answer
    – Raviraj
    Commented Aug 20, 2019 at 14:01

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.