Integrating XML code into HTML website using API platform

  • mayagatewood
  • Born
  • Born
  • mayagatewood
  • Posts: 1

Post 3+ Months Ago

Hi All,
I'm designing an ecommerce website using my web hosting company's site builder and some light html code. But I am using a 3rd party company to fulfill orders and their CreateOrder API passes along fulillment order details directly to your Shopping Cart. With XML API, developers can instantly submit unpaid orders that are ready for processing. I am working on an extrememly tight deadline to have the website completed by this Friday. I am COMPLETELY lost and have no idea how to write, obtain or use the XML code to integrate their API platform into my website. Any assistance suggestions would be greatly appreciated. Below are a few examples of what I was sent in order to setup:

CreateOrder Input Example
XML Code: [ Select ]
<?xml version="1.0" encoding="utf-8"?>
<OrderForm>
   <Auth>
      <key>4028a0e356acc947fcd2bfbf00cef11e128d484a</key>
   </Auth>
   <Order>
      <fullname>John Smith</fullname>
      <address1>78 Franklin Street</address1>
      <address2></address2>
      <city>New York</city>
      <postal>10004</postal>
      <state>NY</state>
      <country>United States</country>
      <sku>1000000</sku>
      <size>Large</size>
      <color>Black</color>
      <quantity>1</quantity>
      <priorityShipping>0</priorityShipping>
      <comments></comments>
   </Order>
</OrderForm>
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <OrderForm>
  3.    <Auth>
  4.       <key>4028a0e356acc947fcd2bfbf00cef11e128d484a</key>
  5.    </Auth>
  6.    <Order>
  7.       <fullname>John Smith</fullname>
  8.       <address1>78 Franklin Street</address1>
  9.       <address2></address2>
  10.       <city>New York</city>
  11.       <postal>10004</postal>
  12.       <state>NY</state>
  13.       <country>United States</country>
  14.       <sku>1000000</sku>
  15.       <size>Large</size>
  16.       <color>Black</color>
  17.       <quantity>1</quantity>
  18.       <priorityShipping>0</priorityShipping>
  19.       <comments></comments>
  20.    </Order>
  21. </OrderForm>


PHP:
Sample Code - Function
This basic cURL PHP example is an easy way to prepare and transmit your XML code for processing.
PHP Code: [ Select ]
<?php  
    function xml_post($post_xml, $url, $port) {
        $user_agent = $_SERVER['HTTP_USER_AGENT'];
        $ch = curl_init(); // initialize curl handle
        curl_setopt($ch, CURLOPT_URL, $url); // set url to post to
        curl_setopt($ch, CURLOPT_FAILONERROR, 1); // Fail on errors
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // allow redirects
        curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); // return into a variable
        curl_setopt($ch, CURLOPT_PORT, $port); //Set the port number
        curl_setopt($ch, CURLOPT_TIMEOUT, 15); // times out after 15s
        curl_setopt($ch, CURLOPT_POSTFIELDS, $post_xml); // add POST fields
        curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
        if($port==443) {
            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
        }
        $data = curl_exec($ch);
        curl_close($ch);
        return $data;
    }
    ?>
  1. <?php  
  2.     function xml_post($post_xml, $url, $port) {
  3.         $user_agent = $_SERVER['HTTP_USER_AGENT'];
  4.         $ch = curl_init(); // initialize curl handle
  5.         curl_setopt($ch, CURLOPT_URL, $url); // set url to post to
  6.         curl_setopt($ch, CURLOPT_FAILONERROR, 1); // Fail on errors
  7.         curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // allow redirects
  8.         curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); // return into a variable
  9.         curl_setopt($ch, CURLOPT_PORT, $port); //Set the port number
  10.         curl_setopt($ch, CURLOPT_TIMEOUT, 15); // times out after 15s
  11.         curl_setopt($ch, CURLOPT_POSTFIELDS, $post_xml); // add POST fields
  12.         curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
  13.         if($port==443) {
  14.             curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
  15.             curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  16.         }
  17.         $data = curl_exec($ch);
  18.         curl_close($ch);
  19.         return $data;
  20.     }
  21.     ?>



Sample Code - XML:
This XML sample code shows how easy it is to post customer order information, with some extra details.
XML Code: [ Select ]
<?xml version="1.0" encoding="utf-8"?>
<OrderForm>
   <Auth>
      <key>4028a0e356acc947fcd2bfbf00cef11e128d484a</key>
   </Auth>
   <Order>
      <fullname>John Smith</fullname>
      <address1>78 Franklin Street</address1>
      <address2></address2>
      <city>New York</city>
      <postal>10004</postal>
      <state>NY</state>
      <country>United States</country>
      <sku>1000000</sku>
      <size>Large</size>
      <color>Black</color>
      <quantity>1</quantity>
      <priorityShipping>0</priorityShipping>
      <comments>print on the back of the t-shirt.</comments>
   </Order>
</OrderForm>
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <OrderForm>
  3.    <Auth>
  4.       <key>4028a0e356acc947fcd2bfbf00cef11e128d484a</key>
  5.    </Auth>
  6.    <Order>
  7.       <fullname>John Smith</fullname>
  8.       <address1>78 Franklin Street</address1>
  9.       <address2></address2>
  10.       <city>New York</city>
  11.       <postal>10004</postal>
  12.       <state>NY</state>
  13.       <country>United States</country>
  14.       <sku>1000000</sku>
  15.       <size>Large</size>
  16.       <color>Black</color>
  17.       <quantity>1</quantity>
  18.       <priorityShipping>0</priorityShipping>
  19.       <comments>print on the back of the t-shirt.</comments>
  20.    </Order>
  21. </OrderForm>


Sample Code - Posting The XML
PHP Code: [ Select ]
<?php echo xml_post($XML, "https://thecompany/api/CreateOrder/", "443"); ?>
Moderator Remark: Please remember to put code bbcode around code so it formats correctly. I added this for you on this post.
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9089
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

Honestly some of this stuff can get very complicated as you would need to extract the details to pass to your fulfillment company out of whatever back-end or scripts you are using, and then once you have the data format it in a way that your API is requiring you to use. If you have little to no experience with programming this may be very difficult and frustrating task for you. If however, you do actually understand how to do PHP and how XML works, then you just need to get in your script and find the right time to have this information transmitted to your fulfillment company, and then implement the code and replace their sample data with code that gets the required information from your orders.

If this is over the top for you I would recommend you hire someone to do this for you, especially if you are on a tight deadline.

Post Information

  • Total Posts in this topic: 2 posts
  • Users browsing this forum: No registered users and 73 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.