Link to home
Start Free TrialLog in
Avatar of -RobRoy-
-RobRoy-

asked on

Connecting to UPS Real-time Rates by XML in ASP

I'm trying to connect to UPS and get a rate for shipping.  So below is the XML that UPS gives you. I need to connect to their server https://www.ups.com.app/xml/rate. I don't know how to use XML inside of ASP to get the ups rate.

Does any one have an example to connect to UPS and get the rates in XML for ASP?

Heres the xml to Access UPS / Below is to get the rates.  

Thanks!

<?xml version="1.0"?>
<AccessRequest xml:lang="en-US">
 <AccessLicenseNumber>TEST262223144CAT</AccessLicenseNumber>
 <UserId>testUser</UserId>
 <Password>testPW</Password>
</AccessRequest>

<!-- RATES --->
<?xml version="1.0"?>
<RatingServiceSelectionRequest xml:lang="en-US">
<Request>
... <Package>
    <PackagingType>
      <Code>02</Code>
      <Description>Package</Description>
    </PackagingType>
    <Description>Rate Shopping</Description>
    <PackageWeight>
      <Weight>33</Weight>
    </PackageWeight>
   </Package>
  <ShipmentServiceOptions/>
</Shipment>
</RatingServiceSelectionRequest>
Avatar of SynergyMedia
SynergyMedia

What you do is post the xml data (both parts) as one long string to the UPS server.  This data is used by UPS to figure out what it is you want.

Then it returns you back a response as a string (which is xml formatted).  Load this string into an XML DOM and parse it from there.

A component to use for Post and Response can be:
Set objInet = server.CreateObject("InetCtls.Inet")

search google for info on using this control

An Quick Example:
set objInet = server.CreateObject("InetCtls.Inet")
objInet.protocol = 4
objInet.accesstype = 1
objInet.requesttimeout = 60
strURL = "(the ups url)"
strHead = "Content-type: (the type required)" & vbCrLf
strInput = "(all that xml)"
objInet.Execute strURL,"POST",strInput,strHead

Lookup how to get a response.  Lookup how to load the response and parse it as XML.

-- James O'Reilly

Avatar of -RobRoy-

ASKER

I cannot create that component on my server (Verio).  I tried it on my local server and kept getting a "malformed URL" error.  

I was trying to use Microsoft.XMLHTTP before, but don't know how to SEND that XML over to UPS first.  Any more tips?
ASKER CERTIFIED SOLUTION
Avatar of SynergyMedia
SynergyMedia

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks James.  I have a one more related question.

<RatingServiceSelectionResponse>
    <RatedShipment>
        <TotalCharges>
            <CurrencyCode>USD</CurrencyCode>
            <MonetaryValue>109.14</MonetaryValue>
        </TotalCharges>

I am trying to pull out the MonetaryValue.  There may be more than one TotalCharges and/or MonetaryValue also, so I have to make sure I get this unique one.  I can do it like this (below), but is there a more direct way to access that?  And do you have a good XMLDOM website?

Set NodeList = xmlDoc.documentElement.getElementsByTagName("TotalCharges")
For Each Elem In NodeList
  If Elem.parentNode.nodeName = "RatedShipment" Then
    GetUPSPricing = Elem.lastchild.text
  End If
Next