Product Import/Insertion using Volusion API

2019-04-16 05:16发布

I am trying to Import/insert my products to my product table in volusion through the Volusion API I have used the sample PHP code provided by Volusion.

    $file = file_get_contents('C:\Users\Ray\Desktop\3.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://.servertrust.com/net/WebService.aspx?Login=support@mysite.com&EncryptedPassword=1234&Import=Insert";

    $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;

This code works great as long as my xml file is under 10MB wich is the limit for the regular import. When I try to import anything over I receive this error:

<ReturnResult>
<Success>False</Success>
<Message>Maximum request length exceeded.</message>
</ReturnResults>Send Failure: Connection was reset

Is there anyway to get around this limit? Like I stated the code works great until I hit the 10MB limit when I receive this error. The current file I am trying to import is only 30MB. Any script or solution that increase the size of file???

标签: php volusion
2条回答
【Aperson】
2楼-- · 2019-04-16 05:22

You're going to have to break up the file. I find that I can't import more than 10 or so products at a time without running into curl timeout errors (error code 28).

查看更多
爷的心禁止访问
3楼-- · 2019-04-16 05:27

You can also write a script that break you file before uploading into small chunks. For more detail you can visit the link below.

Splitting a file before upload

Remember one thing that your script not change the format of the file from their original form for example the file is in json form so the chunk must be in json form.

You can also send dynamically products to your Volusion API.

Another reason can be the price plan because I have also faced that type of issue, at that time my volusion (store) plan was MINI. For price plans and what rights the plan have, you can visit this link.

Volusion price plan and their rights

查看更多
登录 后发表回答