Magento – magento2 soap web service error

magento2soap

I created script like this.and I have created token also from admin side.

ini_set('display_errors',1);
require('vendor/zendframework/zend-server/src/Client.php');
require('vendor/zendframework/zend-soap/src/Client.php');
require('vendor/zendframework/zend-soap/src/Client/Common.php');
$token = "e3wcugwhdhqoxccwdli8yxepaih5lm3b";
$opts = ['http' => ['header' => "Authorization: Bearer " . $token]];
$context = stream_context_create($opts);

$wsdlUrl = "http://192.168.11.175/magento2/soap?wsdl&services=customerAccountManagementV1,customerCustomerRepositoryV1";
$serviceArgs = array("customerId" => 1);

$soapClient = new \Zend\Soap\Client($wsdlUrl);
$soapClient->setSoapVersion(SOAP_1_2);
$soapClient->setStreamContext($context);
$soapResponse = $soapClient->customerCustomerRepositoryV1GetById($serviceArgs);
var_dump($soapResponse);

and I’m getting following error when i run the script.

Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://192.168.11.175/magento2/soap?wsdl&services=customerAccountManagementV1,customerCustomerRepositoryV1' : failed to load external entity "http://192.168.11.175/magento2/soap?wsdl&services=customerAccountManagementV1,customerCustomerRepositoryV1" in /var/www/html/magento2/vendor/zendframework/zend-soap/src/Client/Common.php:37 Stack trace: #0 /var/www/html/magento2/vendor/zendframework/zend-soap/src/Client/Common.php(37): SoapClient->SoapClient('http://192.168....', Array) #1 /var/www/html/magento2/vendor/zendframework/zend-soap/src/Client.php(1023): Zend\Soap\Client\Common->__construct(Array, 'http://192.168....', Array) #2 /var/www/html/magento2/vendor/zendframework/zend-soap/src/Client.php(1195): Zend\Soap\Client->_initSoapClientObject() #3 /var/www/html/magento2/vendor/zendframework/zend-soap/src/Client.php(1106): Zend\Soap\Client->getSoapClient() #4 /var/www/html/magento2/soapcall.php(16): Zend\Soap\Client->__call('cus in /var/www/html/magento2/vendor/zendframework/zend-soap/src/Client/Common.php on line 37

Best Answer

@sivakumar :

  1. $token must be the 'Access Token' in System->Integration->YourApiUserDetail. NOT the 'Access Token Secret'.

  2. Check your Magento's base_url. Is it "http://192.168.11.175/magento2/"?

  3. If domain gives the error, then u can set it in your host file.