We help IT Professionals succeed at work.
Get Started

Classic ASP and UPS API with XML

Slim81
Slim81 asked
on
1,262 Views
Last Modified: 2012-05-11
Hey guys and gals,
I am stuck.  XML is a bit confusing to me.... I have found the code posted below on a different site, but I can't seem to get it to work....  It just returns an empty select box.  I have x'd out my UPS details, for this post.

What am I missing here?
Is there any way to see where the error exists with the XML (ie telling me a line number)?

Here is the code:
<% Response.Buffer=True %>
<%
sAccessLicenseNumber = "xxxxxx"
sUserID = "xxxxxx"
sPassword = "xxxxxx"

DrawUPSRates "33", "50021"

Sub DrawUPSRates(sWeight, sDestinationPostalCode)

  sUPSXML = BuildUPSXML(sWeight, sDestinationPostalCode)

  'Now pass the request to UPS
  Set xmlhttp = Server.CreateObject("MSXML2.ServerXMLHTTP")
  xmlhttp.Open "POST","https://wwwcie.ups.com/ups.app/xml/Rate",false
  xmlhttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
  xmlhttp.send sUPSXML

  sResponseXML = xmlhttp.responseText
  Set mydoc=Server.CreateObject("Microsoft.xmlDOM")
  mydoc.loadxml(sResponseXML)
  'Create a select table from the response xml
  response.Write("<select name='shipping'>")
  'Create A Nodelist of All The RatedShipments
  Set NodeList = mydoc.documentElement.selectNodes("RatedShipment")
  For x = 0 To NodeList.length - 1
    sDisplayString = _
    GetFriendlyUPSName(NodeList.Item(x).selectSingleNode("Service/Code").Text) & _
    " - $" & NodeList.Item(x).selectSingleNode("TotalCharges/MonetaryValue").Text
    Response.Write("<option>")
    Response.Write
    Response.Write("</option>")
  Next
  Response.Write("</select>")
End Sub

Function BuildUPSXML(sWeight, sDestinationPostalCode)
  sShipperPostalCode = "63126"
 
  sXML = sXML & "<?xml version='1.0'?>"
  sXML = sXML & "    <AccessRequest xml:lang='en-US'>"
  sXML = sXML & "        <AccessLicenseNumber>" & sAccessLiscenseNumber & _
                "</AccessLicenseNumber>"
  sXML = sXML & "        <UserId>" & sUserID & "</UserId>"
  sXML = sXML & "        <Password>" & sPassword & "</Password>"
  sXML = sXML & "    </AccessRequest>"
  sXML = sXML & "<?xml version='1.0'?>"
  sXML = sXML & "    <RatingServiceSelectionRequest xml:lang='en-US'>"
  sXML = sXML & "        <Request>"
  sXML = sXML & "            <TransactionReference>"
  sXML = sXML & "                <CustomerContext>Rating and " & _
                "Service</CustomerContext>"
  sXML = sXML & "                <XpciVersion>1.0001</XpciVersion>"
  sXML = sXML & "            </TransactionReference>"
  sXML = sXML & "            <RequestAction>Rate</RequestAction>"
  sXML = sXML & "            <RequestOption>shop</RequestOption>"
  sXML = sXML & "        </Request>"
  sXML = sXML & "        <PickupType>"
  sXML = sXML & "            <Code>01</Code>"
  sXML = sXML & "        </PickupType>"
  sXML = sXML & "        <Shipment>"
  sXML = sXML & "            <Shipper>"
  sXML = sXML & "                <Address>"
  sXML = sXML & "                    <PostalCode>" & sShipperPostalCode & _
                "</PostalCode>"
  sXML = sXML & "                </Address>"
  sXML = sXML & "            </Shipper>"
  sXML = sXML & "            <ShipTo>"
  sXML = sXML & "                <Address>"
  sXML = sXML & "                    <PostalCode>" & sDestinationPostalCode & _
                "</PostalCode>"
  sXML = sXML & "                </Address>"
  sXML = sXML & "            </ShipTo>"
  sXML = sXML & "            <Service>"
  sXML = sXML & "                <Code>11</Code>"
  sXML = sXML & "            </Service>"
  sXML = sXML & "            <Package>"
  sXML = sXML & "                <PackagingType>"
  sXML = sXML & "                    <Code>02</Code>"
  sXML = sXML & "                    <Description>Package</Description>"
  sXML = sXML & "                </PackagingType>"
  sXML = sXML & "                <Description>Rate Shopping</Description>"
  sXML = sXML & "                <PackageWeight>"
  sXML = sXML & "                    <Weight>" & sWeight & "</Weight>"
  sXML = sXML & "                </PackageWeight>"
  sXML = sXML & "            </Package>"
  sXML = sXML & "            <ShipmentServiceOptions/>"
  sXML = sXML & "        </Shipment>"
  sXML = sXML & "</RatingServiceSelectionRequest>"
 
  BuildUPSXML = Replace(sXML, vbTab, "")
End Function

Function GetFriendlyUPSName(vCode)
  Select Case vCode
    Case "01"
      GetFriendlyUPSName = "UPS Next Day Air"
    Case "02"
      GetFriendlyUPSName = "UPS 2nd Day Air"
    Case "03"
      GetFriendlyUPSName = "UPS Ground"
    Case "07"
      GetFriendlyUPSName = "UPS Worldwide Express"
    Case "08"
      GetFriendlyUPSName = "UPS Worldwide Expedited"
    Case "11"
      GetFriendlyUPSName = "UPS Standard"
    Case "12"
      GetFriendlyUPSName = "UPS 3 Day Select"
    Case "13"
      GetFriendlyUPSName = "UPS Next Day Air Saver"
    Case "14"
      GetFriendlyUPSName = "UPS Next Day Air Early A.M."
    Case "54"
      GetFriendlyUPSName = "UPS Worldwide Express Plus"
    Case "59"
      GetFriendlyUPSName = "UPS 2nd Day Air A.M."
    Case "65"
      GetFriendlyUPSName = "UPS Saver"
  End Select
End Function

%>

Open in new window


Any help would be appreciated!
Comment
Watch Question
Top Expert 2011
Commented:
This problem has been solved!
Unlock 1 Answer and 4 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE