Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: d85e325d18
Fetching contributors…

Cannot retrieve contributors at this time

60 lines (52 sloc) 2.67 kb
<?xml version="1.0" encoding="UTF-8"?>
<table xmlns="http://query.yahooapis.com/v1/schema/table.xsd">
<meta>
<author>César Rodas</author>
<description>Extract shipping costs for USPS</description>
<documentationURL>http://www.marksanborn.net/php/calculating-usps-shipping-rates-with-php/</documentationURL>
<sampleQuery>select * from {table} where orig_zip='60606' and dest_zip = '01452' and weight='17' and api_id = "1234567";</sampleQuery>
</meta>
<bindings>
<select itemPath="RateV2Response.Package.Postage" produces="XML">
<urls>
<url>http://production.ShippingAPIs.com/ShippingAPI.dll</url>
</urls>
<inputs>
<key id='weight' type='xs:number' paramType='variable' required="true" />
<key id='orig_zip' type='xs:string' paramType='variable' required="true" />
<key id='dest_zip' type='xs:string' paramType='variable' required="true" />
<key id='api_id' type='xs:string' paramType='variable' required="true"/>
<key id='password' type='xs:string' paramType='variable' />
<key id='ounces' type='xs:number' paramType='variable' />
<key id='service' type='xs:string' paramType='variable' />
<key id='size' type='xs:string' paramType='variable' />
</inputs>
<execute><![CDATA[
if (!password) {
password = "xxxxxxx";
}
if (!service) {
service = "PRIORITY";
}
if (!size) {
size = "REGULAR";
}
if (!ounces) {
ounces = 0;
}
var content = "API=RateV2&XML=<RateV2Request USERID=\"" + api_id + "\" PASSWORD=\"" + password + "\"><Package ID=\"0\"><Service>" + service + "</Service><ZipOrigination>" + orig_zip + "</ZipOrigination><ZipDestination>" + dest_zip + "</ZipDestination><Pounds>" + weight + "</Pounds><Ounces>" + ounces + "</Ounces><Size>" + size + "</Size><Machinable>TRUE</Machinable></Package></RateV2Request>";
var html = request.post(content).response;
/* Remove <?xml ....?> */
/* It return a valid XML, but the wrong content type */
var remove = html.search(/\?\>/);
if (remove) {
for (i = remove; html[i] != '<'; i++);
html = html.substr(i);
}
xml = XML(html);
response.object = xml
]]>
</execute>
</select>
</bindings>
</table>
Jump to Line
Something went wrong with that request. Please try again.