2

I'm trying to get all products in $productArrarray from magento 2 API via SOAP client. I tried the below function but it throws this error:

Error:

SOAP-ERROR: Parsing WSDL: Couldn't load from 'https://shop.mysite.com/soap/default?wsdl&services=catalogProductRepositoryV1' : failed to load external entity "https://shop.mysite.com/soap/default?wsdl&services=catalogProductRepositoryV1"

Code:

public function getMagentoProducts() {
 $productArr = array('' => 'Select Product');
 try {
 $request = new SoapClient("https://shop.mysite.com/soap/?wsdl&services=integrationAdminTokenServiceV1", array("soap_version" => SOAP_1_2));
 $token = $request->integrationAdminTokenServiceV1CreateAdminAccessToken(array("username"=>"user", "password"=>"pass"));
 $opts = array(
 'http'=>array(
 'header' => 'Authorization: Bearer '.json_decode($token->result),
 'user_agent' => 'PHPSoapClient'
 ),
 'ssl' => array(
 'verify_peer' => false,
 'verify_peer_name' => false,
 'allow_self_signed' => true
 )
 );
 $wsdlUrl = 'https://shop.mysite.com/soap/default?wsdl&services=catalogProductRepositoryV1';
 $context = stream_context_create($opts);
 $soapClientOptions = array(
 'stream_context' => $context,
 'cache_wsdl' => WSDL_CACHE_NONE
 );
 libxml_disable_entity_loader(false);
 $soapClient = new SoapClient($wsdlUrl, ['version' => SOAP_1_2, 'context' => $soapClientOptions]);
 var_dump($soapClient);exit;
 $soapResponse = $soapClient->__getFunctions();
 } catch (Exception $e) {
 $this->forward404($e->getMessage());
 }
 }
asked Jul 10, 2018 at 16:27

2 Answers 2

1

If you are using a development site with an SSL that is not signed by a major CA, then when PHP goes to load external entities from your domain, your SSL certificate can cause this error.

I just had to add my root CA certificate that signed my SSL to the trusted roots of my server and the error went away.

For Ubuntu 16.04 I added the PEM version of my root CA to /usr/local/share/ca-certificates then ran sudo update-ca-certificates and it was added.

answered Jul 16, 2018 at 20:58
0

I made this error go away by enabling the php module openssl (Windows server)

answered Sep 29, 2021 at 11:48
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.