?
Solved

Accessing the UPS API with ASP....

Posted on 2009-12-22
1
Medium Priority
?
506 Views
Last Modified: 2012-05-08
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

0
Comment
Question by:engineroom
1 Comment
 
LVL 14

Accepted Solution

by:
_Stilgar_ earned 2000 total points
ID: 26342224
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

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Loops Section Overview
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question