I was just trying to make the Magento Core API web service to work so I could write my own automated scripts to perform scheduled manipulations on the entire database (products, attributes, categories, customers, etc.) of my Magento store. And when I tried the example here to list some of the products, it gave me this SoapClient error:
Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://www.example.com/api/soap/?wsdl' : Extra content at the end of the document in \www\mapi.php:4 Stack trace: #0 \www\mapi.php(4): SoapClient->SoapClient('http://www.exam...') #1 {main} thrown in \www\mapi.php on line 4
Did some searches and finally solved the problem. What you need to do is to first download the WSDL file from your Magento installation with cURL and then open it with SoapClient rather than download the file with SoapClient.
This is the modified PHP code from the official example:
$curl = curl_init('http://www.example.com/api/soap/?wsdl');
curl_setopt($curl,CURLOPT_RETURNTRANSFER, true);
$wsdl_string = curl_exec($curl);
file_put_contents('temp.xml',$wsdl_string);
try
{
$proxy = new SoapClient('temp.xml');
$sessionId = $proxy->login('yourApiUser', 'yourApiKey');
$filters = array(
'sku' => array('like'=>'%')
);
$products = $proxy->call($sessionId, 'product.list', array($filters));
var_dump($products);
}
catch (Exception $e)
{
print '<pre>';
var_dump(libxml_get_last_error());
print '</pre>';
}
Just change ‘www.example.com’, ‘yourApiUser’ and ‘yourApiKey’ to your own.