No announcement yet.

3dCart API / XML

  • Filter
  • Time
  • Show
Clear All
new posts

  • 3dCart API / XML


    Hopefully I posted this question in the correct forum category.

    I am in need of assistance with the 3dCart API. I plan to use the updateProductInventory method to update inventory levels throughout the day.

    As an overview, we are a B2B distributor of janitorial products and we purchase our products from a wholesaler who drop-ships direct to the end consumer. The wholesaler publishes an updated inventory file every hour that we need to use to update inventory in our 3dCart store. We do not want a product being purchased if the wholesaler is out of stock.

    I wrote a VBScript program that downloads the inventory file (pipe delimited text file) from their FTP server and the program then parses out the information I need and generates a .txt file in a format that 3dCart can successfully import via the Inventory update located in Product > Export/Inventory program. I have 3dCart configured to hide the “Buy Now” button if there is no inventory.

    Now I need to automate this manual process and I believe the API can do this for me….if I can figure how to implement it. Below is what I have done so far.

    I wrote a program that generates a request XML file in the format as the updateProductInventory sample in the API documentation. I enabled API in the shopping cart and have the auto-generated userkey. Below is a sample XML file :

    <?xml version="1.0" encoding="utf-8"?> 
    <soap:Envelope xmlns:xsi="" 
        <updateProductInventory xmlns=""> 
          <userKey>xxxxx</userKey> (Removed userkey- Gonzalo Gil)
          <productId>ACE 12408</productId> 
    Not knowing exactly what the next step is I uploaded this XML file to my Assets directory and then browsed to and it appears to at least process the file but the inventory update does not take place.

    My questions are:
    • Where do I upload the XML file to?
    • How do I actually go about processing the XML file?
    • How do I make this XML file get processed automatically on some interval? In other words, what is the catalyst that causes 3dCart to process the XML file?

    Any advice is greatly appreciated. If what I described is not clear I will do my best to better explain it.

    Thank you!

  • #2
    Hi Msteed,
    A couple of things:

    #1 - Please do not post credentials on the forum, you just gave everyone your userkey and so giving them access to use your api unless you protected it by ip as well. I suggest you go and change the api KEY.

    #2 - What you have there is the XML that you need to send to the web service. Here is a link to something that you can use to learn more about this:

    Essentially you are POSTING that XML string to a web service, the web service responds with an XML giving you an "OK" or a "ERROR". You would make a vbscript that looped through your inventory file (CSV/mdb/sql), and for each one, makes the XML string, and posts it to the service. Then get a response, if response is OK, then it was successful, move to next, if not, log the error so you know that part was not updated. The only reason the update would fail is if the part # can not be found.

    If you can not get it to work, we have developers that can write the code for you for a fee, you could send sample of the database you have from your distributor to [email protected] and we can get you a quote.
    Gonzalo Gil
    3dCart Support
    800-828-6650 x111


    • #3
      More Information on API/XML

      Thought I would add a bit of a tutorial to this subject to get folks going on this. Following is a working example of using PhP and the 3D API.

      NOTE: I have changed the API key value so this code won't work if you cut and paste. You have to use your own STORE URL and API Key.

      Hope this helps someone else untangle the API. (P.S. The API documentation could be improved with some real life examples in PhP and ASP code)

      FGluck --

      ------ START HERE -----------

      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
      <html xmlns="">
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
      <title>Example PhP Interface to 3D API SOAP service</title>

      // build the Soap XML to submit to the 3D API SOAP service.
      // The PhP reference and examples for soapClient is here:
      // You can see how your PhP is configured and what is included by using the simple statement
      // phpinfo();.

      // Turn on some error reporting
      ini_set('display_errors', true);
      // Now define the SOAP client using the url for the service. This service is from
      // The service provides a number of interfaces to the 3D cart database. See the URL above from complete info
      // from this page, click on Service Description ( to see the WSDL
      // service of the description.

      // first, we create a soap client with trace on so that we can later see the results.
      // trace allow us to see the results of the calls later (see below)
      // more informaton on the SimpleXML library for PhP and how to create a soapclient is at
      $client = new soapclient('', array('trace' => 1,
      'soap_version' => SOAP_1_1));

      // Parameters passed to the call must be in an array so we now create that array
      // NOTE: the name of the elements must EXACTLY match what the service expects (including upper and lower case).
      // If the names do not match, the service throws them out.
      // The ONLY way to find exactly what the service expects is to look at the service description at
      // this URL

      $param = array(
      // your UserKey is set from your admin panel. The API service must be enabled and you
      // have to have a valid key in order to use this service

      // We then call the service ($client), passing the parameters and the name of the operation that we want the server to execute
      // the result is assigned to a variable called $result
      $result = $client->getProductCount($param);

      // Then we use three standard PHP SimpleXML library calls to see the results
      // print the SOAP request
      echo '<h2>SOAP Request</h2><pre>' . htmlspecialchars($client->__getLastRequest(), ENT_QUOTES) . '</pre>';
      // print the SOAP request Headers
      echo '<h2>SOAP Request Headers</h2><pre>' . htmlspecialchars($client->__getLastRequestHeaders(), ENT_QUOTES) . '</pre>';
      // print the SOAP response
      echo '<h2>SOAP Response</h2><pre>' . htmlspecialchars($client->__getLastResponse(), ENT_QUOTES) . '</pre>';

      // Results are returned in an array that contains one item -- a stdClass object.
      // We look at all the results using print_r after we check if the call was successful assess the results
      if (is_soap_fault($result)) {
      echo '<h2>Fault</h2><pre>';
      echo '</pre>';
      } else {
      echo '<h2>Result Data Structure:</h2><pre>';
      echo '</pre>';

      // as shown by the print_r results, what we get back is an object that contains an array
      // The Array contains one stdClass Object called GetProductCountResult
      // That object in turn contains properties
      // We show the outcome property of specific variables in that object by printing it

      echo "<br/><strong>There are a total of:</strong> ".$result->getProductCountResult->any." products that were found<br/>";

      ----- END CODE ---


      • #4
        Thanks for the example code. Very helpful.