0

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?

  • i just fund another module is blocking the soap create product. – hkguile May 19 '15 at 9:26
  • if your php version 5.6, you can get some errors in SOAP. Using different version may help you. – John Jun 13 '16 at 11:48
  • 1
    @hkguile May i know how you solved the issue? – zus Nov 10 '18 at 12:14
2

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());
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.