Magento – Fatal error: Uncaught SoapFault exception: [Client] looks like we got no XML document

soap

i'm trying to use magento soapV2 to create product, here is the script:

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<?php


// Magento login information 
$mage_url = 'http://localhost/first/api/v2_soap?wsdl=1'; 

$mage_user = 'rayapi'; 
$mage_api_key = 'Abcd1234'; 
// Initialize the SOAP client 
$client = new SoapClient( $mage_url ); 

$session = $client->login( $mage_user, $mage_api_key );


$catalogProductCreateEntity = new stdClass();
$additionalAttrs = array();

$catalogProductCreateEntity->name = "product name";
$catalogProductCreateEntity->description = "description";
$catalogProductCreateEntity->short_description = "desc";
$catalogProductCreateEntity->status = "1";
$catalogProductCreateEntity->price = "99";
$catalogProductCreateEntity->tax_class_id = "2";
$catalogProductCreateEntity->websites = array(1,2);
$catalogProductCreateEntity->categories = array(7,15);
$catalogProductCreateEntity->status = 1;
$catalogProductCreateEntity->price = 45;
$catalogProductCreateEntity->tax_class_id = 2;
$catalogProductCreateEntity->weight = 1;

// send the request
$product = $client->catalogProductCreate($session, "simple", 9, 'test_sku', $catalogProductCreateEntity);

// end session and enjoy your updated products :)
$client->endSession($session);

var_dump($product);


?>

Error message:

Fatal error: Uncaught SoapFault exception: [Client] looks like we got no XML document in C:\xampp\htdocs\first\soap.php:71 Stack trace: #0 C:\xampp\htdocs\first\soap.php(71): SoapClient->__call('catalogProductC...', Array) #1 C:\xampp\htdocs\first\soap.php(71): SoapClient->catalogProductCreate('7ab47f189292d99...', 'simple', 9, 'test_sku', Object(stdClass)) #2 {main} thrown in C:\xampp\htdocs\first\soap.php on line 71

i tried use
$result = $client->catalogInventoryStockItemList($session, array('693')); // //Products ID
print_r($result);

catalogInventoryStockItemList is work for me but catalogProductCreate not work.

i googled around but their solution not useful to me, how to solve this problem?

Best Answer

The SoapFault looks like we got no XML document means that the server response is invalid: whitespace before the XML declaration, debug output, no XML at all, whatever…

The server response can be examined via __getLastResponse() call.

Adapted to the OPs code example:

$client = new SoapClient($mage_url, array('trace' => true));

// […]

try {
    $product = $client->catalogProductCreate($session, "simple", 9, 'test_sku', $catalogProductCreateEntity);
} catch (SoapFault $e) {
    print($client->__getLastResponse());
}