ProductSync

From DevWiki

Jump to: navigation, search

ProductSync is a sample program written C# that integrates with the Volusion API. The purpose of this program is to sync the Volusion database with an external database that is used by a customized application. This sample program demonstrates on how to sync Volusion product stock with an external database. This stock sync is done in three steps. First, the program downloads the Volusion stock information through an API request. Second, it calculates the new stock status and uploads the updated changes through an API update request to update the Volusion database. Lastly, it updates the external database for changes.

Contents

Step 1: Download Volusion stock information

api_url = "http://YourUrl/net/WebService.aspx?Login=YourEmail@YourDomain.com&EncryptedPassword=YourPassword&
API_Name=Generic\\Products&SELECT_Columns=p.ProductCode,p.ProductID,p.ProductName,p.StockStatus";

xml_http = new XMLHTTP();
xml_http.open("POST", api_url, false, "", "");
xml_http.send(null);
api_response = xml_http.responseText;

Note that this XML request will only download products that has been modified.

Step 2: Calculate the new stock status and update the Volusion database

The new stock can be calculated by using the formula below:

new_stock = old_stock - (old_stock - volusion_stock) - (old_stock - external_stock)


Once the new stock has been calculated, an API update request can be called. And this is done by the code below:

api_url = "http://YourUrl/net/WebService.aspx
Login=YourEmail@YourDomain.com&EncryptedPassword=YourPassword&Import=Update";
api_request = "";
api_request = api_request + "<?xml version=\"1.0\" encoding=\"utf-8\" ?>";
api_request = api_request + "<xmldata>";
api_request = api_request + "   <Products>";
api_request = api_request + "       <ProductCode>0001</ProductCode>";
api_request = api_request + "       <StockStatus>5</StockStatus>";
api_request = api_request + "   </Products>";
api_request = api_request + "</xmldata>";

xml_http = new XMLHTTP();
xml_http.open("POST", api_url, false, "", "");
xml_http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=utf-8");
xml_http.setRequestHeader("Content-Action", "Volusion_API");
xml_http.send(api_request);
api_response = xml_http.responseText;

Note that this XML request returns a success status. It returns <Success>True</Success> if the update has been commited or <Success>False</Success> if the update failed.

Step 3: Update the external database

Once stock update is successfully completed, the external database can be updated with the new stock status.


Since step one only download products that were recently modified, not all products will be sync. So it is necessary to check products modified in the external database as well and request for an API update. This can be done by the same steps but with a where clause in step one.

Step 1: Download Volusion stock information with a where clause

api_url = "http://YourUrl/net/WebService.aspx?Login=YourEmail@YourDomain.com&EncryptedPassword=YourPassword&
API_Name=Generic\\Products&SELECT_Columns=p.ProductCode,p.ProductID,p.ProductName,p.StockStatus 
&WHERE_Column=p.ProductCode&WHERE_Value=0002";

xml_http = new XMLHTTP();
xml_http.open("POST", api_url, false, "", "");
xml_http.send(null);
api_response = xml_http.responseText;
Navigation