1

I am not able to access product details using SOAP API while i call api url i am getting Error:

Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://127.0.0.1/test_magento_2/soap/default?wsdl&services=catalogProductTypeListV1' : failed to load external entity "http://127.0.0.1/test_magento_2/soap/default?wsdl&services=catalogProductTypeListV1" in /opt/lampp/htdocs/test_magento_2/api.php:59 Stack trace: #0 /opt/lampp/htdocs/test_magento_2/api.php(59): SoapClient->SoapClient('http://127.0.0....', Array) #1 {main} thrown in /opt/lampp/htdocs/test_magento_2/api.php on line 59

I am using magento 2.1.5 and I have also set necessary setting in php.ini files for soap like
extension=php_soap.dll
extension=php_openssl.dll
i am facing this issue in my local system and in live server.

My code for call SOAP API:

$token = 'kxij7mg931mxc3h2hy7dyvxm9m3fy4k4';
$opts = ['http' => ['header' => "Authorization: Bearer " . $token]];
$wsdlUrl = 'http://127.0.0.1/test_magento_2/soap/default?wsdl&services=catalogProductTypeListV1';
$context = stream_context_create($opts);
$soapClient = new SoapClient($wsdlUrl, ['version' => SOAP_1_2, 'context' => $context]);
$soapResponse = $soapClient->__getFunctions();
var_dump($soapResponse);

3 Answers 3

2

Try commenting out the foreach in vendor/magento/framework/Webapi/Authorization.php ( line 36 to 40 )

Should look like this:

public function isAllowed($aclResources)
{
    //foreach ($aclResources as $resource) {
    //    if (!$this->authorization->isAllowed($resource)) {
    //        return false;
    //    }
    //}
    return true;
}

I had the same problem, this fixed it.

1
  • I think we should allow resource from the integration section of API resources. That would do the magic! Jul 5, 2018 at 10:11
1

perhaps you have a error or a missed configuration on permissions,

to check the WSDL comment this line in "Magento\Webapi\Model\AbstractSchemaGenerator":

protected function getAllowedServicesMetadata($requestedServices)
{
    $allowedServicesMetadata = [];
    foreach ($requestedServices as $serviceName) {
        $serviceMetadata = $this->getServiceMetadata($serviceName);
        foreach ($serviceMetadata[ServiceMetadata::KEY_SERVICE_METHODS] as $methodName => $methodData) {
            if (!$this->authorization->isAllowed($methodData[ServiceMetadata::KEY_ACL_RESOURCES])) { 
//Comment

            //    unset($serviceMetadata[ServiceMetadata::KEY_SERVICE_METHODS][$methodName]);
            }
        }
        if (!empty($serviceMetadata[ServiceMetadata::KEY_SERVICE_METHODS])) {
            $this->removeRestrictedRoutes($serviceMetadata);
            $allowedServicesMetadata[$serviceName] = $serviceMetadata;
        }
    }
    return $allowedServicesMetadata;
}
-1

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. ;)

Your Answer

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

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