Forum Moderators: open

Message Too Old, No Replies

UPS XML Rates & Services

need a kind soul

         

mattglet

8:09 am on Mar 5, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



well, it seems my favorite website is my last resort. i am desperately trying to figure out how to implement UPS' XML Rates & Services tool into my site. i run a site that uses ASP, and right now use Americart as my shopping cart utility. i have since built my own shopping cart, but the only thing i am lacking is automatic shipping rates. i have no knowledge of XML, only ASP. if there is ANYONE out there that point me in a free or lost cost direction of how to set this up, i will be in your debt. i am trying to figure out how to get my info (shipping weight, zip code, etc.) to UPS, and then receive the info back. i have contacted UPS, and they said that they cannot help anyone implement, they can only supply the code without support. i guess i'm just looking for one person with a heart of gold to hold my hand. please leave your comments, or sticky mail them to me. thank you in advance for any time you may give.

Xoc

11:37 am on Mar 5, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I didn't even know that the USPS had an interface. Interesting to know. I downloaded the documentation and took a brief look. Unfortunately, their documentation sucks. The pdf file with the supposed instructions, says "copy the sample from this document" except there isn't any sample in the document. They've got some DLL that probably would simplify the access from an ASP page, if you can get it installed on the server (depends on your ISP on whether that is possible).

Anyway, in my brief look, I couldn't tell how easy or hard it is, since I couldn't find the example of the transaction. If you have any pointers to documentation of what the XML request and response should look like, that would help.

macrost

3:07 pm on Mar 5, 2003 (gmt 0)

10+ Year Member



I would be happy to help... however I am lost on ups.com looking for their documentation.
Mac

macrost

3:25 pm on Mar 6, 2003 (gmt 0)

10+ Year Member



ok, forum, here is the code that works. Matt don't worry, I have taken out the sensitive stuff, just thought this would be helpful to others out there.
Mac
;)


<% Response.Buffer=True %>
<%
'dim all of our vars
Dim xml, xsl, template, processor, strXML

'you can build the query dynamically by using request.form or request.querystring, however you want to use it
strXML = "<?xml version='1.0'?><AccessRequest xml:lang='en-US'><AccessLicenseNumber></AccessLicenseNumber><UserId></UserId><Password></Password></AccessRequest><?xml version='1.0'?><RatingServiceSelectionRequest xml:lang='en-US'><Request><TransactionReference><CustomerContext>Rating and Service</CustomerContext><XpciVersion>1.0001</XpciVersion></TransactionReference><RequestAction>Rate</RequestAction><RequestOption>shop</RequestOption></Request><PickupType><Code>01</Code></PickupType><Shipment><Shipper><Address><PostalCode>30076</PostalCode></Address></Shipper><ShipTo><Address><PostalCode>30041</PostalCode></Address></ShipTo><Service><Code>11</Code></Service><Package><PackagingType><Code>02</Code><Description>Package</Description></PackagingType><Description>Rate Shopping</Description><PackageWeight><Weight>33</Weight></PackageWeight></Package><ShipmentServiceOptions/></Shipment></RatingServiceSelectionRequest>"

'this will url encode your request
'strXML = Server.UrlEncode(strXML)

'here's where we send the stuff
Dim xmlhttp
Set xmlhttp = Server.CreateObject("MSXML2.ServerXMLHTTP")
xmlhttp.Open "POST","https://www.ups.com/ups.app/xml/Rate?",false
xmlhttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
xmlhttp.send strXML
Response.Write(xmlhttp.responseText)
'we load into a multi thread object for xsl transformations
Set xml = Server.CreateObject("MSXML2.FreeThreadedDOMDocument.3.0")
xml.async = false
xml.loadXml(xmlhttp.responseText)

'start email success
Dim ObjMail, intMailFormat, strSubject
intMailFormat = 1
strSubject = "good response"
If Not xml Is Nothing Then
If Not xml.documentElement Is Nothing Then
'we are looking for the root node.
If xml.documentElement.nodeName = "RatingServiceSelectionResponse" Then
Set ObjMail = Server.CreateObject("CDONTS.NewMail")
ObjMail.FROM = ""
ObjMail.TO = ""
ObjMail.Subject = strSubject
ObjMail.BodyFormat = intMailFormat
ObjMail.Body = "Your request." & vbcrlf & strXML & vbcrlf & "Your response." & vbcrlf & xmlhttp.responseText
ObjMail.Send
Set ObjMail = Nothing
End If
End If
End If

'load our xsl
Set xsl = Server.CreateObject("MSXML2.FreeThreadedDOMDocument.3.0")
xsl.async = false
Set template = Server.CreateObject("MSXML2.XSLTemplate")

'by using template we can dynamically send params to our xsl
template.stylesheet = xsl
set processor = template.createProcessor()
processor.input = xml

'HERE IS WHERE WE SEND PARAMETERS TO THE XSLT TO CONTINUE
'TO BE ABLE TO ACCESS THE PARAM'S IN THE XSL THE FORMAT IS LIKE THIS AT TOP-LEVEL <xsl:param name="arrivalDate"/>
'yourVar = Request.Form("yourVar")
'If yourVar <> "" Then
' processor.addParameter "yourVar", yourVar
'End If
processor.transform()

'Here is the final transformation to the browser, everything is sent downstream
Response.write (processor.output)

Set xsl = Nothing
Set xml = Nothing
Set xmlhttp = Nothing
Set template = Nothing
%>

DigiMedia

6:07 am on Apr 16, 2003 (gmt 0)

10+ Year Member



macrost,

Man, That code has helped me out! Thanks!

I have posted a question in a different thread about how to work with the response that UPS sends back. If you get a chance to take a look and see what you think I would be much grateful :)

Thanks,
Cody
<no sigs>

[edited by: Xoc at 7:33 pm (utc) on April 16, 2003]
[edit reason] removed sig [/edit]