• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Implement USPS Shipping Rate Calculator

New Here ,
Feb 18, 2010 Feb 18, 2010

Copy link to clipboard

Copied

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

TOPICS
Advanced techniques

Views

2.1K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Feb 19, 2010 Feb 19, 2010

Copy link to clipboard

Copied

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 19, 2010 Feb 19, 2010

Copy link to clipboard

Copied

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="
    ) />

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Feb 19, 2010 Feb 19, 2010

Copy link to clipboard

Copied

<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" />

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 19, 2010 Feb 19, 2010

Copy link to clipboard

Copied

Not sure if I am following you on why we would do that and the difference it would make?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Feb 19, 2010 Feb 19, 2010

Copy link to clipboard

Copied

The cfhttpparam passes in our xml parameter i.e. XML=#strXML#. In other words by including the &XML= in the URL we are duplicating the &XML= in the final URL+its parameters.

We could actually have passed our API value (i.e. API=RateV3) with another cfhttparam as well, leaving our URL as
http://production.shippingapis.com/ShippingAPI.dll

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Feb 19, 2010 Feb 19, 2010

Copy link to clipboard

Copied

Please note that we have also removed the parentheses ( ).

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Feb 19, 2010 Feb 19, 2010

Copy link to clipboard

Copied

I have tried this and it worked.

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

<cfset api = "RateV3" />

<!--- Create the XML data to post. --->

<cfsavecontent variable="strXML">

<RateV3Request USERID="UserName">

  <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>

<cffunction name="processRequest" access="private" returntype="xml" output="false" hint="Makes the HTTP request to the USPS API.">

      <cfargument name="url" type="String" required="true" />

      <cfargument name="api" type="String" required="true" />

      <cfargument name="xml" type="String" required="true" />

      <cfhttp url="#arguments.url#" method="post">

            <cfhttpparam type="formfield" name="api" value="#arguments.api#" />

            <cfhttpparam type="formfield" name="xml" value="#arguments.xml#" />

      </cfhttp>

      <cfreturn XmlParse(cfhttp.fileContent) />

</cffunction>

<!--- Dump results --->

<cfdump var=#processRequest(strURL, api, strXML)# />

     

<!--- Output details --->

<cfoutput>CharSet: #cfhttp.ErrorDetail#<br />

      Filecontent: #cfhttp.Filecontent#<br />

      Header: #cfhttp.Header#<br />

      Mimetype: #cfhttp.Mimetype#<br />

      Statuscode: #cfhttp.Statuscode#<br />

      Text: #cfhttp.Text#<br />

</cfoutput>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Feb 19, 2010 Feb 19, 2010

Copy link to clipboard

Copied

(Disclaimer, I have only skimmed this thread) Before you re-invent the wheel, have you checked riaforge.org? I have not used it myself, but it looks like there is at least one cfc:

http://uspscfc.riaforge.org/

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 21, 2010 Feb 21, 2010

Copy link to clipboard

Copied

LATEST

Sorry for the delay, I did not work on it again till tonight.

A***, Thank you very much for your help, I really appreciate it. I did get it to work with your code and it works great. Thanks

-==cfSearching==- - Thanks for the link, I checked it out and it also does what I need it to do. So both are very helpful.

I also found this one from CFUnite

Mary Jo Sminkey "USPS tracker"

http://wiki.cfunited.com/index.cfm/Open_Source_Contest_Entries#Mary_Jo_Sminkey__USPS_tracker_

All were very helpful in fixing and learning how to handle it.

thank you very much for your time, knowledge and willingness to help me out

CJ

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation