Accessing the UPS API with ASP....

Hey all, i'm trying to integrate this code so that i can use the UPS api. When i run the code i get a response saying that my XML is bad. How do i integrate this UPS api?
<%
ship_to_zip=33323
weight=5
package_length=6
package_width=6
package_height=6
residential=true
 
 
xml_request= "<?xml version='1.0'?>"
xml_request = xml_request & "<accessRequest xml:lang='en-US'>"
xml_request = xml_request & "<accessLicenseNumber>YOUR_ACCESS_LICENSE_NUMBER</accessLicenseNumber>"
xml_request = xml_request & "<userId>YOUR_USER_NAME</userId>"
xml_request = xml_request & "<password>YOUR_PASSWORD</password>"
xml_request = xml_request & "</accessRequest>"
 
xml_request = xml_request & "<?xml version='1.0'?>"
xml_request = xml_request & "<ratingServiceSelectionRequest xml:lang='en-US'>"
xml_request = xml_request & "<request>"
xml_request = xml_request & "<transactionReference>"
xml_request = xml_request & "<customerContext>Rating and Service</customerContext>"
xml_request = xml_request & "<xpciVersion>1.0001</xpciVersion>"
xml_request = xml_request & "</transactionReference>"
xml_request = xml_request & "<requestAction>Rate</requestAction>"
xml_request = xml_request & "<requestOption>Rate</requestOption>"
xml_request = xml_request & "</request>"
xml_request = xml_request & "<pickupType>"
xml_request = xml_request & "<code>01</code>"
xml_request = xml_request & "</pickupType>"
xml_request = xml_request & "<shipment>"
xml_request = xml_request & "<shipper>"
xml_request = xml_request & "<shipperNumber>YOUR_SHIPPER_NUMBER</shipperNumber>"
xml_request = xml_request & "<address>"
xml_request = xml_request & "<postalCode>YOUR_POSTAL_CODE</postalCode>"
xml_request = xml_request & "</address>"
xml_request = xml_request & "</shipper>"
xml_request = xml_request & "<shipTo>"
xml_request = xml_request & "<address>"
xml_request = xml_request & "<postalCode>" & ship_to_zip & "</postalCode>"
if (residential) then
xml_request = xml_request & "<residentialAddressIndicator/>"
end if
xml_request = xml_request & "</address>"
xml_request = xml_request & "</shipTo>"
xml_request = xml_request & "<service>"
xml_request = xml_request & "<code>" & ups_code & "</code>"
xml_request = xml_request & "</service>"
xml_request = xml_request & "<package>"
xml_request = xml_request & "<packagingType>"
xml_request = xml_request & "<code>02</code>"
xml_request = xml_request & "<description>Package</description>"
xml_request = xml_request & "</packagingType>"
xml_request = xml_request & "<description>Rate Shopping</description>"
xml_request = xml_request & "<packageWeight>"
xml_request = xml_request & "<weight>" & weight & "</weight>"
xml_request = xml_request & "</packageWeight>"
xml_request = xml_request & "<dimensions>"
xml_request = xml_request & "<length>" & package_length & "</length>"
xml_request = xml_request & "<width>" & package_width & "</width>"
xml_request = xml_request & "<height>" & package_height & "</height>"
xml_request = xml_request & "</dimensions>"
xml_request = xml_request & "</package>"
xml_request = xml_request & "<shipmentServiceOptions/>"
xml_request = xml_request & "</shipment>"
xml_request = xml_request & "</ratingServiceSelectionRequest>"
 
'uncomment to see response in case of error
'response.write xml_request

URLToRSS = "https://wwwcie.ups.com/ups.app/xml/Rate"
 
Set xmlHttp = Server.CreateObject("MSXML2.ServerXMLHTTP.3.0")
' resolve, connect, send, receive - in milliseconds
xmlHttp.setTimeouts 10000, 60000, 10000, 10000
xmlHttp.Open "Post", URLToRSS, false
 
xmlHttp.Send(xml_request)
set RSSXML = xmlHttp.ResponseXML
 
Set xmlDOM = Server.CreateObject("MSXML2.DOMDocument.3.0")
xmlDOM.async = false
xmlDOM.setProperty "SelectionLanguage", "XPath"
xmlDOM.Load(RSSXML)
 
if xmlDOM.parseError.errorCode <> 0 then
 
response.write "DOM Not Loaded"
 
end if
 
'check for error
xmlQuery = "*/Error"
 
set errorNode = xmlDOM.documentElement.selectNodes(xmlQuery)
 
if not errorNode is nothing then
	errorLength = errorNode.length
		if errorLength > 0 then
			rate_error_severity= errorNode.item(0).selectSingleNode("ErrorSeverity").nodeTypedValue
			rate_error_code= errorNode.item(0).selectSingleNode("ErrorCode").nodeTypedValue
			rate_error_description= errorNode.item(0).selectSingleNode("ErrorDescription").nodeTypedValue
		end if
end if
 
if rate_error_severity="Hard" then
 
	total= 0
	rate_error= rate_error_description
	'response.end()

else
 
rate_error=""
 
xmlQuery = "/RatingServiceSelectionResponse/RatedShipment"
set docHeadlines = xmlDOM.documentElement.selectNodes(xmlQuery)
 
total= docHeadlines.item(0).selectSingleNode("TotalCharges").selectSingleNode("MonetaryValue").nodeTypedValue
GuaranteedDaysToDelivery= docHeadlines.item(0).selectSingleNode("GuaranteedDaysToDelivery").nodeTypedValue
ScheduledDeliveryTime= docHeadlines.item(0).selectSingleNode("ScheduledDeliveryTime").nodeTypedValue
 
end if
%>

Open in new window

LVL 3
engineroomAsked:
Who is Participating?
 
_Stilgar_Connect With a Mentor Commented:
This is because your XML is bad indeed. You have 2 xml headers (lines 10 and 17), and from the looks of it the structure is bad as well.

Lines 10-65 are constructing the XML. When put into a blank file (without the ASP codes) the file should be loaded into a tree in any browser; if the browser will throw a parsing error you will be able to see where it is. This is your way to go.

Another option is to follow UPS's samples carefully.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.