Reputation: 4076
My shipping quote api for USPS is working for USA zip codes only. Canada, United Kingdom and other international zip codes result in this error: Microsoft VBScript runtime error '800a01a8' Object required: xmlRate.selectSingleNode(...)' /folder/subfolder/usps_plugin.asp, line 32.
Here is the code for that file:
<%
function GetUSPSRate(SourceZip, DestZip, Weight, Method)
dim xml
dim post
post = "<RateV4Request USERID='MYUSPSUSERNAME'>" & _
"<Revision/>" & _
"<Package ID='1ST'>" & _
"<Service>" & Method & "</Service>" & _
"<ZipOrigination>" & SourceZip & "</ZipOrigination>" & _
"<ZipDestination>" & DestZip & "</ZipDestination>" & _
"<Pounds>" & Weight & "</Pounds>" & _
"<Ounces>0</Ounces>" & _
"<Container>RECTANGULAR</Container>" & _
"<Size>LARGE</Size>" & _
"<Width>12</Width>" & _
"<Length>12</Length>" & _
"<Height>12</Height>" & _
"<Girth>12</Girth>" & _
"</Package>" & _
"</RateV4Request>"
set xml = CreateObject("MSXML2.ServerXMLHTTP")
xml.open "GET", "http://production.shippingapis.com/ShippingAPI.dll?API=RateV4&XML=" & post
xml.send("")
dim xmlRate
set xmlRate = xml.responseXML
GetUSPSRate = xmlRate.selectSingleNode("//Rate").text
end function
function GetUSPSRates(SourceZip, DestZip, Weight)
dim rates
set rates = CreateObject("Scripting.Dictionary")
rates.add "USPS Express", GetUSPSRate(SourceZip, DestZip, Weight, "EXPRESS")
rates.add "USPS Priority", GetUSPSRate(SourceZip, DestZip, Weight, "PRIORITY")
' rates.add "USPS First Class", GetUSPSRate(SourceZip, DestZip, Weight, "FIRST CLASS")
set GetUSPSRates = rates
end function
%>
Also, here is the code that calls for that request:
dim uspsRates
dim uspsKey
set uspsRates = GetUSPSRates("02196", receiverpostalcode, shipmentweight)
for each uspsKey in uspsRates
dim uspsValue
uspsValue = uspsRates.item(uspsKey)
%>
<input name="shipinfo" type="radio" value="<%= uspsValue %>|<%= uspsKey %>">$<%= uspsValue + stone_handlingfee %> <%= uspsKey %>
<br>
<% next
%>
It works perfectly and flawlessly for domestic zip codes, however, international is when the issues occur. Constructive input is greatly appreciated.
Upvotes: 0
Views: 131
Reputation: 4076
Not all the variables were accounted for to generate international quotes. Country, City and Zip are the most important. Without these, the api could not return results.
Upvotes: 1