{"id":38,"date":"2008-08-21T11:34:29","date_gmt":"2008-08-21T18:34:29","guid":{"rendered":"http:\/\/www.nayansavla.com\/blog\/?p=38"},"modified":"2008-08-21T11:34:29","modified_gmt":"2008-08-21T18:34:29","slug":"getting-shipping-rates-from-usps","status":"publish","type":"post","link":"https:\/\/www.nayansavla.com\/blog\/?p=38","title":{"rendered":"Getting Shipping Rates from USPS"},"content":{"rendered":"<p>I have been working on a Flash\/Flex shopping cart which uses <a href=\"http:\/\/www.amfphp.org\/\" target=\"_blank\">AMFPHP<\/a> to connect with <a href=\"http:\/\/oscommerce.com\/\" target=\"_blank\">OSCommerce<\/a> and you can manage your cart using OScommerce.\u00a0<\/p>\n<p>\u00a0<\/p>\n<p>The client wanted to get shipping prices based on the weight and it had to be USPS. It turned out to be a really easy integration, I have used Flex but it would be the same using Flash as well.\u00a0<\/p>\n<p>\u00a0<\/p>\n<p>The only problem is when you hit the testing server of USPS they expect the xml to be exactly the same as they specify in the examples and also Rate3 API&#8217;s don&#8217;t work well. Shown below is the simple Flex code to get response from the testing server,<\/p>\n<p>\u00a0<\/p>\n<p>&lt;?xml version=&#8221;1.0&#8243; encoding=&#8221;utf-8&#8243;?&gt;<\/p>\n<p>&lt;mx:Application xmlns:mx=&#8221;http:\/\/www.adobe.com\/2006\/mxml&#8221; layout=&#8221;absolute&#8221; creationComplete=&#8221;sendService()&#8221;&gt;<\/p>\n<p>\u00a0\u00a0 \u00a0&lt;mx:Script&gt;<\/p>\n<p>\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0&lt;![CDATA[<\/p>\n<p>\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0import mx.controls.Alert;<\/p>\n<p><span> <\/span><\/p>\n<p>\u00a0\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0private function errorMsg(info:Object):void{<\/p>\n<p>\u00a0\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0\u00a0 \u00a0var data:Object = info;<\/p>\n<p>\u00a0\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0}<span> <\/span><\/p>\n<p><span> <\/span><\/p>\n<p>\u00a0\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0private function gotBack(event:Object):void{<\/p>\n<p>\u00a0\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0\u00a0 \u00a0var data:Object = event;<\/p>\n<p>\u00a0\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0\u00a0 \u00a0mx.controls.Alert.show(event.result.Error.Description);<\/p>\n<p>\u00a0\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0}<\/p>\n<p><span> <\/span><\/p>\n<p><span> <\/span><\/p>\n<p>\u00a0\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0private function sendService():void{<\/p>\n<p>\u00a0\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0\u00a0 \u00a0var xmlData:String = &#8216;&lt;RateV2Request USERID=&#8221;xxxxxx&#8221;&gt;&lt;Package\u00a0\u00a0\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0ID=&#8221;0&#8243;&gt;&lt;Service&gt;PRIORITY&lt;\/Service&gt;&#8217; +\u00a0<\/p>\n<p>\u00a0\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0\u00a0 \u00a0 \u00a0 \u00a0 &#8216;&lt;ZipOrigination&gt;10022&lt;\/ZipOrigination&gt;&lt;ZipDestination&gt;20008&lt;\/ZipDestination&gt;&#8217;\u00a0\u00a0\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0 \u00a0 \u00a0 \u00a0+\u00a0&#8216;&lt;Pounds&gt;10&lt;\/Pounds&gt;&lt;Ounces&gt;5&lt;\/Ounces&gt;&lt;Container&gt;Flat Rate\u00a0Box&lt;\/Container&gt;&lt;Size&gt;REGULAR&lt;\/Size&gt;&lt;\/Package&gt;&lt;\/RateV2Request&gt;&#8217;;<\/p>\n<p>\u00a0\u00a0 \u00a0 \u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0var requestObj:Object = new Object();<\/p>\n<p>\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0 \u00a0 \u00a0requestObj.XML = new XML(xmlData).toXMLString();<\/p>\n<p>\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0requestObj.API = &#8220;RateV2&#8221;;<\/p>\n<p>\u00a0\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0\u00a0 \u00a0upsService.request = requestObj;<\/p>\n<p>\u00a0\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0upsService.send();<\/p>\n<p>\u00a0\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0}<\/p>\n<p><span> <\/span>]]&gt;<\/p>\n<p>&lt;\/mx:Script&gt;<\/p>\n<p><span> <\/span><\/p>\n<p><span> <\/span><\/p>\n<p><span> <\/span>&lt;mx:HTTPService id=&#8221;upsService&#8221; url=&#8221;http:\/\/testing.shippingapis.com\/ShippingAPITest.dll&#8221; result=&#8221;gotBack(event)&#8221;<\/p>\n<p><span> <\/span>\u00a0 fault=&#8221;errorMsg(event)&#8221; resultFormat=&#8221;e4x&#8221; \/&gt;<\/p>\n<p>&lt;\/mx:Application&gt;<\/p>\n<p>\u00a0<\/p>\n<p>As you can see there is not much to it, you just have to use a simple httpservice and the parameters required is the XML and the API. You can request upto 25 rates and the details can be found on the usps site out <a href=\"http:\/\/www.usps.com\/webtools\/htm\/RateCalculatorsv20.htm\" target=\"_blank\">here<\/a>.<\/p>\n<p>\u00a0<\/p>\n<p>USPS will return an XML even if there is an error and for production you have to move to a different server but the basic things still remain the same. Now only if they would have a crossdomain.xml on their servers, have put in a request for that but i doubt they would be willing to have it. *sigh*<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I have been working on a Flash\/Flex shopping cart which uses AMFPHP to connect with OSCommerce and you can manage your cart using OScommerce.\u00a0 \u00a0 The client wanted to get shipping prices based on the weight and it had to be USPS. It turned out to be a really easy integration, I have used Flex [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[66,45],"class_list":["post-38","post","type-post","status-publish","format-standard","hentry","category-flex","tag-flex","tag-usps"],"_links":{"self":[{"href":"https:\/\/www.nayansavla.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/38","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.nayansavla.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.nayansavla.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.nayansavla.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.nayansavla.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=38"}],"version-history":[{"count":0,"href":"https:\/\/www.nayansavla.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/38\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.nayansavla.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=38"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.nayansavla.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=38"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.nayansavla.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=38"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}