troubleshooting Question

Classic ASP and UPS API with XML

Avatar of Slim81
Slim81Flag for United States of America asked on
ASPXML
4 Comments1 Solution1269 ViewsLast Modified:
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!
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 4 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros