2

Could you help me to understand how to add new products to Volusion using the Volusion API in PHP with something like cURL?

Any useful links will be appreciated.

Ruslan Osmanov
  • 20,486
  • 7
  • 46
  • 60
Debugger
  • 491
  • 4
  • 21

1 Answers1

1
  1. Make XML file in the format like this with name "myXML.txt".

<Import>
   <Products>
      <ProductID>360</ProductID>
      <productcode>10035</productcode>
      <vendor_partno>035</vendor_partno>
      <productname>Asus Video Card ATI Doulat</productname>
      <listprice>6.95</listprice>
      <productprice>2</productprice>
      <vendor_price>3.83</vendor_price>
      <stockstatus>100</stockstatus>
      <upc_code>99999</upc_code>
      <categoryids>107,134</categoryids>
      <productdescriptionshort />
      <productdescription />
      <productweight>0.00</productweight>
      <freeshippingitem />
      <minqty />
      <maxqty />
   </Products>
</Import>
  1. Then copy and paste this in your editor

<?php

    $file = file_get_contents('myXML.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 = "https://www.xxxxxusa.com/net/WebService.aspx?Login=xxxx@xxxxxxxcom.com&EncryptedPassword=0000000000000000000000000000xxxxxxxxxx&Import=Update";

//  Create the Header   

    $header  = array(
    "MIME-Version: 1.0",
    "Content-type: text/xml; charset=utf-8",
    "Content-transfer-encoding: text",
    "Request-number: 1",
    "Document-type: Request",
    "Interface-Version: Test 1.4"
);

    //  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, $header);
    $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;
?>

Remember this use your own API credential. Try this hope you got the answer.

Doulat Khan
  • 493
  • 5
  • 24
  • 1
    Thanks for your attention I will definitely try this :) – Debugger Oct 26 '16 at 10:59
  • I have got the following error False One or more of the following elements in your XML file is invalid: Import. The most likely reason is that you have embedded HTML tags or invalid characters (e.g., ampersands), and have not enclosed the elements in CDATA tags. For more information, please see any XML reference. 1 even in xml we do not have any '&' sign – Debugger Oct 27 '16 at 21:16
  • Can you post your error in comment?? you just post i will correct it for future help. – Doulat Khan Oct 28 '16 at 06:41
  • i have resolved the error. posted above with Using CDATA and Removing Volusion_API keyword and doing some refactoring in xml data thanks. – Debugger Oct 31 '16 at 11:10
  • can u share your XML – Doulat Khan Oct 31 '16 at 11:16
  • here is my XML which is working fine https://codepad.co/snippet/zFDWWxuy – Debugger Oct 31 '16 at 18:07
  • One of friend says that my products are inserted but not show on the store front end. – Doulat Khan Nov 01 '16 at 05:59
  • I think Product is there in store but he is unable to find them He can download the products excel sheet and then find the product code there as it will be easy to find something in excel sheet. – Debugger Nov 01 '16 at 06:29
  • no no bro the products are not shows on the front end of the store when he search his products. when i try thats true that products are inserted but when i search on my front store search i cant fine. i m working on it. – Doulat Khan Nov 01 '16 at 07:24
  • Actually volusoin search criteria is not as much good therefor I was asking to use excel sheet. Anyhow Good luck. – Debugger Nov 01 '16 at 09:23
  • excel means?? any how i m trying to find the way for him – Doulat Khan Nov 01 '16 at 09:41
  • Is it possible to pass more than one products xml file bcoz one person raised this issue. – Doulat Khan Nov 01 '16 at 10:39