Magento API SoapClient Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn’t load from…

Magento Go: Open Your Online Store for Free!

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.

Premium Magento Theme: Avalanche Grab the latest premium Magento theme: Avalanche to kick-start your store! Get to know it and you will definitely look no further. Use coupon code:

MAGENTOGOREVIEW
Click To Open/Copy
To get 15% exclusive discount for MagentoGoReview.com readers.

Magento Go Shopping Cart
Use these 3 promo codes to get lifetime discount off Magento Go!


Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>