I'm trying to get all products in $productArr
array 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());
}
}