Salman Zafar Salman Zafar - 5 days ago 5
PHP Question

How to create new categories in Volusion using Volusion API

Actually I have a store and importing products and categories both from my vendor store to my store, the products are inserted and updated successfully but the categories are not inserted and updated.

I want to create/add new category through API.

My category.txt file.



<?xml version="1.0"?>
<Volusion_API>
<Categories_Products_Link>
<CategoryID>107</CategoryID>
<ProductID>63015</ProductID>
</Categories_Products_Link>
</Volusion_API>





Here is my cURL script of Importing.



<?php
$file = file_get_contents('category.txt', true);

// Create the Xml to POST to the Webservice

$Xml_to_Send = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>";
$Xml_to_Send .= "<Volusion_API>";
// $Xml_to_Send .= "<!--";
$Xml_to_Send .= $file;
// $Xml_to_Send .= "\"\"";
// $Xml_to_Send .= "-->";
$Xml_to_Send .= "</Volusion_API>";


$url = "http://mysitedomian/net/WebService.aspx?Login=xxxxxxxxxxx&EncryptedPassword=xxxxxxxxx&Import=Insert-Update";


// Create the Header

// Post and Return Xml
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $Xml_to_Send);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type:application/x-www-form-urlencoded; charset=utf-8", "Content-Action:Volusion_API"));
$data = curl_exec($ch);

// Check for Errors
if (curl_errno($ch)){

print curl_error($ch);
} else {

curl_close($ch);
}

// Display the Xml Returned on the Browser

echo $data;

?>




Answer

Just remove the following from your category.txt this

<?xml version="1.0"?>
<Volusion_API></Volusion_API>

Because it is already defined in your cURL script, and Volusion API not support double defined tags.

Remove the above and pass to your cURL script and run the cURL script it will work.

Comments