Skip to main content
CJ83_2
Known Participant
February 19, 2010
Question

Implement USPS Shipping Rate Calculator

  • February 19, 2010
  • 1 reply
  • 2468 views

I need to get rates for shipping from USPS, but I can not get the API to work. Below is the code and links to the page. Does anyone know of a tutorial or can help me figure out what the problem is. I only get HTTP Error 501 - Not Implemented

USPS instructions: http://www.usps.com/webtools/htm/Rate-Calculators-v2-3.htm#_Toc220743995

Page where the below code runs: http://www.wrathclothingstore.com/cfhttp.cfm

CODE:


    <cfset strURL = (
    "http://testing.shippingapis.com/ShippingAPITest.dll?API=RateV3&XML="
    ) />

<!--- Create the XML data to post. --->
<cfsavecontent variable="strXML">
<RateV3Request USERID="xxxxUserNameGoesHerexxxx">

    <Package ID="1ST">

        <Service>FIRST CLASS</Service>

        <FirstClassMailType>LETTER</FirstClassMailType>

        <ZipOrigination>44106</ZipOrigination>

        <ZipDestination>20770</ZipDestination>

        <Pounds>0</Pounds>

        <Ounces>3.5</Ounces>

        <Size>REGULAR</Size>

        <Machinable>true</Machinable>

    </Package>

    <Package ID="2ND">

        <Service>PRIORITY</Service>

        <ZipOrigination>44106</ZipOrigination>

        <ZipDestination>20770</ZipDestination>

        <Pounds>1</Pounds>

        <Ounces>8</Ounces>

        <Container>NONRECTANGULAR</Container>

        <Size>LARGE</Size>

        <Width>15</Width>

        <Length>30</Length>

        <Height>15</Height>

        <Girth>55</Girth>

    </Package>

    <Package ID="3RD">

        <Service>ALL</Service>

        <ZipOrigination>90210</ZipOrigination>

        <ZipDestination>96698</ZipDestination>

        <Pounds>8</Pounds>

        <Ounces>32</Ounces>

        <Container/>

        <Size>REGULAR</Size>

        <Machinable>true</Machinable>

    </Package>

</RateV3Request>

</cfsavecontent>



<!---
    Post the XML data to catch page. We are going
    to post this value as an XML object will actually
    just post it as an XML body.
--->
<cfhttp
    url="#strURL#"
    method="POST"
    useragent="#CGI.http_user_agent#"
    result="objGet">

    <!---
        When posting the xml data, remember to trim
        the value so that it is valid XML.
    --->
    <cfhttpparam
        type="XML"
        value="#strXML.Trim()#"
        />

</cfhttp>


<!--- Output the return message. --->
<cfoutput>

CharSet: #objGet.ErrorDetail#<BR>
Filecontent: #objGet.Filecontent#<BR>
Header: #objGet.Header#<BR>
Mimetype: #objGet.Mimetype#<BR>
Statuscode: #objGet.Statuscode#<BR>
Text: #objGet.Text#<BR>
<!--- <cfdump var="#objGet#"> --->
</cfoutput>

Any help would be greatly appreciated. Been banging my head agaist the wall!!

Thanks

CJ

This topic has been closed for replies.

1 reply

Inspiring
February 19, 2010
CJ83_2
CJ83_2Author
Known Participant
February 19, 2010

Thanks, but I upgraded and moved to the production server and it still does not work. I checked out your second link and it is PHP and I not know PHP so I am having a hard time trying to figure it out so I could make it work with CF

If I put this in the the URL (Address Bar) It works fine:

http://production.shippingapis.com/ShippingAPI.dll?API=RateV3&XML=%20%20%20%3CRateV3Request%20USERID=%22xxxUSERNAMExxx%22%3E%20%20%3CPackage%20ID=%221%22%3E%20%20%3CService%3EPRIORITY%3C/Service%3E%20%20%3CZipOrigination%3E44656%3C/ZipOrigination%3E%20%20%3CZipDestination%3E44663%3C/ZipDestination%3E%20%20%3CPounds%3E0%3C/Pounds%3E%20%20%3COunces%3E12%3C/Ounces%3E%20%20%3CSize%3EREGULAR%3C/Size%3E%20%20%3C/Package%3E%20%3C/RateV3Request%3E

It brings back the shipping rate. But when I do it in the my application, nothing, I get the NOT IMPLEMENTED  (HTTP Error 501) Is there an error in my CF code above, what am I doing wrong?

I changed the strXML line of code to this for production:

<cfset strURL = (
    "http://production.shippingapis.com/ShippingAPI.dll?API=RateV3&XML="
    ) />

Inspiring
February 19, 2010
<cfset strURL = (

    "http://production.shippingapis.com/ShippingAPI.dll?API=RateV3&XML="
    ) />

Let us remove the &XML= from our strURL as below:

<cfset strURL = "http://production.shippingapis.com/ShippingAPI.dll?API=RateV3" />