-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>TEST2 62223144CA T</AccessL icenseNumb er>
<UserId>testUser</UserId>
<Password>testPW</Password >
</AccessRequest>
<!-- RATES --->
<?xml version="1.0"?>
<RatingServiceSelectionReq uest xml:lang="en-US">
<Request>
... <Package>
<PackagingType>
<Code>02</Code>
<Description>Package</Desc ription>
</PackagingType>
<Description>Rate Shopping</Description>
<PackageWeight>
<Weight>33</Weight>
</PackageWeight>
</Package>
<ShipmentServiceOptions/>
</Shipment>
</RatingServiceSelectionRe quest>
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>TEST2
<UserId>testUser</UserId>
<Password>testPW</Password
</AccessRequest>
<!-- RATES --->
<?xml version="1.0"?>
<RatingServiceSelectionReq
<Request>
... <Package>
<PackagingType>
<Code>02</Code>
<Description>Package</Desc
</PackagingType>
<Description>Rate Shopping</Description>
<PackageWeight>
<Weight>33</Weight>
</PackageWeight>
</Package>
<ShipmentServiceOptions/>
</Shipment>
</RatingServiceSelectionRe
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?
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks James. I have a one more related question.
<RatingServiceSelectionRes ponse>
<RatedShipment>
<TotalCharges>
<CurrencyCode>USD</Currenc yCode>
<MonetaryValue>109.14</Mon etaryValue >
</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.get ElementsBy TagName("T otalCharge s")
For Each Elem In NodeList
If Elem.parentNode.nodeName = "RatedShipment" Then
GetUPSPricing = Elem.lastchild.text
End If
Next
<RatingServiceSelectionRes
<RatedShipment>
<TotalCharges>
<CurrencyCode>USD</Currenc
<MonetaryValue>109.14</Mon
</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.get
For Each Elem In NodeList
If Elem.parentNode.nodeName = "RatedShipment" Then
GetUPSPricing = Elem.lastchild.text
End If
Next
You can find more info on using the XMLDOM here:
http://www.devguru.com/Technologies/xmldom/quickref/xmldom_index.html
http://www.devguru.com/Technologies/xmldom/quickref/xmldom_index.html
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("InetC
search google for info on using this control
An Quick Example:
set objInet = server.CreateObject("InetC
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,str
Lookup how to get a response. Lookup how to load the response and parse it as XML.
-- James O'Reilly