Copy link to clipboard
Copied
Hi,
Has anybody implemented/worked with FedEx web services in CF? I'm looking for sample CF code consuming FedEx web services (v 7), such as get rates info, get rate services, etc.
Many thanks in advance.
Copy link to clipboard
Copied
This project was recently (Oct 2009) updates for v7:
http://code.google.com/p/cffedexrates/
Looks like it would help you out.
Copy link to clipboard
Copied
This project was recently (Oct 2009) updates for v7:
http://code.google.com/p/cffedexrates/
+1
Though I have not used it, I would definitely take a look at that project. The FedEx web services have a lot of nesting and complex types which can be very tough to work with. AFAIK that project uses the simpler soap/cfhttp approach to send requests, which is simpler to construct and easier to debug IMO.
-Leigh
Copy link to clipboard
Copied
Great. I'll take a look at it. Many thanks.
Copy link to clipboard
Copied
Great. I'll take a look at it. Many thanks.
Copy link to clipboard
Copied
Hello, have you actually used that link and it worked? I have really been having trouble. Fedex says it works on their end, but I keep getting errors. If you could help me, I would greatly appreciate it.
I have used post url to https://gatewaybeta.fedex.com:443/web-services and I have used post url to https://gatewaybeta.fedex.com:443/xml. Each on gives me a different error.
The /web-services page returns "9999: Empty web-service request, unable to determine service."
The /xml page returns "Invalid transaction type. Transaction could not be routed."
Here is my cfhttp request...
<cfhttp method="POST" url="https://gatewaybeta.fedex.com:443/web-services" port="443" throwonerror="no">
<cfhttpparam name="Referer" type="HEADER" value="Cobbler Lady" />
<cfhttpparam name="Host" type="HEADER" value="https://gatewaybeta.fedex.com:443" />
<cfhttpparam name="Accept" type="HEADER" value="image/gif, image/jpeg, image/pjpeg, text/plain, text/html, text/xml, */*" />
<cfhttpparam name="Content-Type" type="HEADER" value="content-type:
text/xml; charset='UTF-8';" />
<cfhttpparam name="Content-Length" type="HEADER" value="#vContentLen#" />
<cfhttpparam name="RateRequest" type="HEADER" value="#XMLPacket#">
</cfhttp>
And here is my XMLPacket value:
<ns:RateRequest xmlns:ns="http://fedex.com/ws/rate/v7"><ns:WebAuthenticationDetail><ns:UserCredential> <ns:Key>WPGnimalBRMCmBM8</ns:Key> <ns:Password>7tvCDvC5o7n81cjdT4ZVvvAr4</ns:Password> </ns:UserCredential> </ns:WebAuthenticationDetail><ns:ClientDetail> <ns:AccountNumber>510088000</ns:AccountNumber> <ns:MeterNumber>118506050</ns:MeterNumber> </ns:ClientDetail> <ns:TransactionDetail> <ns:CustomerTransactionId>CobblerLady_IDentifier</ns:CustomerTransactionId> </ns:TransactionDetail> <ns:Version> <ns:ServiceId>crs</ns:ServiceId> <ns:Major>7</ns:Major> <ns:Intermediate>0</ns:Intermediate> <ns:Minor>0</ns:Minor> </ns:Version> <ns:ReturnTransitAndCommit>true</ns:ReturnTransitAndCommit> <ns:CarrierCodes>FDXG</ns:CarrierCodes> <ns:RequestedShipment> <ns:ShipTimestamp>2010-01-16T09:00:43</ns:ShipTimestamp> <ns:DropoffType>REGULAR_PICKUP</ns:DropoffType> <ns:ServiceType>FIRST_OVERNIGHT</ns:ServiceType> <ns:PackagingType>YOUR_PACKAGING</ns:PackagingType> <ns:TotalWeight> <ns:Units>LB</ns:Units> <ns:Value>2</ns:Value> </ns:TotalWeight> <ns:TotalInsuredValue> <ns:Currency>USD</ns:Currency> <ns:Amount>40</ns:Amount> </ns:TotalInsuredValue> <ns:Shipper> <ns:Address> <ns:StreetLines>1234 Shipper Address</ns:StreetLines> <ns:StreetLines></ns:StreetLines> <ns:City>Los Angeles</ns:City> <ns:StateOrProvinceCode>CA</ns:StateOrProvinceCode> <ns:PostalCode>90000</ns:PostalCode> <ns:CountryCode>US</ns:CountryCode> </ns:Address> </ns:Shipper> <ns:Recipient> <ns:Address> <ns:StreetLines>1234 Able Stree</ns:StreetLines> <ns:StreetLines> No. 5</ns:StreetLines> <ns:City>Anywhere</ns:City> <ns:StateOrProvinceCode>CA</ns:StateOrProvinceCode> <ns:PostalCode>90750</ns:PostalCode> <ns:CountryCode>US</ns:CountryCode> </ns:Address> </ns:Recipient> <ns:ShippingChargesPayment> <ns:PaymentType>SENDER</ns:PaymentType> <ns:Payor> <ns:AccountNumber></ns:AccountNumber> </ns:Payor> </ns:ShippingChargesPayment> <ns:RateRequestTypes>ACCOUNT</ns:RateRequestTypes> <ns:PackageCount>1</ns:PackageCount> <ns:PackageDetail>INDIVIDUAL_PACKAGES</ns:PackageDetail> <ns:RequestedPackageLineItems> <ns:SequenceNumber>1</ns:SequenceNumber> <ns:InsuredValue> <ns:Currency>USD</ns:Currency> <ns:Amount>40</ns:Amount> </ns:InsuredValue> <ns:Weight> <ns:Units>LB</ns:Units> <ns:Value>2</ns:Value> </ns:Weight> </ns:RequestedPackageLineItems> </ns:RequestedShipment> </ns:RateRequest>
Copy link to clipboard
Copied
<cfhttpparam name="Content-Type"
type="HEADER" value="content-type:
text/xml; charset='UTF-8';" />
I did not try your code yet, but did you happen to post a comment on that project's issue page? If so, the problem may be your headers. I noticed two of them are combined, which seems to cause problems. Try using 's charset attribute to specify utf-8, and set the content-type (text/xml) only via <cfhttpparam
Copy link to clipboard
Copied
Thanks so much for your reply. Here is what I did, but same error "Invalid transaction type. Transaction could not be routed.".
Do you think it has something to do with my XMLPacket?
Copy link to clipboard
Copied
Did you post some new code (ie with the headers fixed)? If so, it is not visible in the forums.
Copy link to clipboard
Copied
Sorry about that. I put the code in the email, but it didn't come over. Here is my new cfhttp post. Is it correct?
<cfhttp method="POST" url="https://gatewaybeta.fedex.com:443/xml" port="443" throwonerror="no">
<cfhttpparam name="Referer" type="HEADER" value="Cobbler Lady" />
<cfhttpparam name="Host" type="HEADER" value="https://gatewaybeta.fedex.com:443" />
<cfhttpparam name="Accept" type="HEADER" value="image/gif, image/jpeg, image/pjpeg, text/plain, text/html, text/xml, */*" />
<cfhttpparam name="Content-Type" type="HEADER" value="text/xml" />
<cfhttpparam name="charset" type="HEADER" value="UTF-8" />
<cfhttpparam name="Content-Length" type="HEADER" value="#vContentLen#" />
<cfhttpparam name="RateRequest" type="HEADER" value="#XMLPacket#">
</cfhttp>
Copy link to clipboard
Copied
<cfhttpparam name="charset"
type="HEADER" value="UTF-8" />
Try moving the charset declaration to the cfhttp tag instead (not cfhttpparam). "Charset" should be an attribute of cfhttp.
Copy link to clipboard
Copied
<cfhttp method="POST" url="https://gatewaybeta.fedex.com:443/xml" port="443" throwonerror="no" charset="UTF-8">
Nope...same error. Here is the page I am running...
http://www40.safesecureweb.com/cobblerlady/shiptrack.cfm
Copy link to clipboard
Copied
Well, you modified the original project code and added a bunch of extra headers and code in there. So I suspect that is why it is not working for you.
What happens when you try the original code from http://code.google.com/p/cffedexrates/ with no modifications other than substituting your credentials?
Copy link to clipboard
Copied
BTW: If you are using v7, use the updated code. Because the original still uses v5.
Updated code
http://code.google.com/p/cffedexrates/issues/detail?id=2
Copy link to clipboard
Copied
Simple as that - it works...thank you so much. I was using their XML documentation and I thought it said we needed a lot of extra headers.
Thanks again.
Copy link to clipboard
Copied
You are very welcome.
- Leigh
Copy link to clipboard
Copied
higginswork,
I followed the example in the link, http://code.google.com/p/cffedexrates/, but I'm getting an error "Method Not Allowed".
Thanks.
Copy link to clipboard
Copied
Can you post the code you are using, error message, and which version number v5 or v7?
Copy link to clipboard
Copied
Hi ==cfSearching==,
Looks like I'm assigned to work in this project again after being removed from it for a while. I'll post the code I'm using, error message, and which version number v5 or v7 when I return to work tomorrow.
Many thanks in advance.
Copy link to clipboard
Copied
Hi ==cfSearching==,
The error message I'm getting is: Authentication Failed
Below is the code I'm using (v7), but according to FedEx Web Services Resource Center, they are on version 8. Is this why I'm getting the error?
FedexRates_v7.cfc (downloaded from here: http://code.google.com/p/cffedexrates/😞
<cfcomponent>
<!---
***** ColdFusion FedEx Rate Component *****
http://code.google.com/p/cffedexrates/downloads
Original Developer: Brandon Wolf, FusionAge Inc. (BrandonWolf@FusionAge.com) http://www.fusionage.com
Feel free to modify this script, but I would appreciate it if you left the credits
See INFO.TXT for detailed information on this Component
--->
<cffunction name="getRates" access="public" returntype="struct" output="true">
<!---VALIDATION -- YOU MUST FILL THIS IN WITH YOUR INFORMATION FROM FEDEX--->
<cfargument name="myKey" type="string" required="no" default="3SelgyCFGbsOLWcN">
<cfargument name="myPassword" type="string" required="no" default="xkfWm7p0eSGk6NqL7Qy5Ctahd">
<cfargument name="myAccountNo" type="string" required="no" default="510087704">
<cfargument name="myMeterNo" type="string" required="no" default="118511767">
<cfargument name="sandbox" type="boolean" required="no" default="true">
<!---Shipper (Sender) Details--->
<cfargument name="shipperAddress1" type="string" required="yes">
<cfargument name="shipperAddress2" type="string" required="no" default="">
<cfargument name="shipperCity" type="string" required="yes">
<cfargument name="shipperState" type="string" required="yes">
<cfargument name="shipperZip" type="string" required="yes">
<cfargument name="shipperCountry" type="string" required="no" default="US">
<!---Ship To (Recipient) Details--->
<cfargument name="shipToAddress1" type="string" required="yes">
<cfargument name="shipToAddress2" type="string" required="no" default="">
<cfargument name="shipToCity" type="string" required="yes">
<cfargument name="shipToState" type="string" required="yes">
<cfargument name="shipToZip" type="string" required="yes">
<cfargument name="shipToCountry" type="string" required="yes" default="US">
<cfargument name="shipToResidential" type="boolean" required="no" default="false">
<!---Package Details--->
<cfargument name="pkgWeight" type="numeric" required="yes">
<cfargument name="pkgValue" type="numeric" required="yes">
<cfargument name="pkgLength" type="numeric" required="no" default="0">
<cfargument name="pkgWidth" type="numeric" required="no" default="0">
<cfargument name="pkgHeight" type="numeric" required="no" default="0">
<cfset var XMLPacket = "" />
<cfset var fedexUrl = "" />
<cfset var xmlFile = "" />
<cfset var cfhttp = "" />
<cfset var err = "" />
<cfset var fedexReply = "" />
<cfset var n = "" />
<cfset var r = "" />
<!---Build the XML Packet to send to FedEx--->
<cfsavecontent variable="XMLPacket"><cfoutput>
<ns:RateRequest xmlns:ns="http://fedex.com/ws/rate/v7" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ns:WebAuthenticationDetail>
<ns:UserCredential>
<ns:Key>#arguments.myKey#</ns:Key>
<ns:Password>#arguments.myPassword#</ns:Password>
</ns:UserCredential>
</ns:WebAuthenticationDetail>
<ns:ClientDetail>
<ns:AccountNumber>#arguments.myAccountNo#</ns:AccountNumber>
<ns:MeterNumber>#arguments.myMeterNo#</ns:MeterNumber>
</ns:ClientDetail>
<ns:Version>
<ns:ServiceId>crs</ns:ServiceId>
<ns:Major>7</ns:Major>
<ns:Intermediate>0</ns:Intermediate>
<ns:Minor>0</ns:Minor>
</ns:Version>
<ns:RequestedShipment>
<ns:ShipTimestamp>#DateFormat(Now(),'yyyy-mm-dd')#T#TimeFormat(Now(),'hh:mm:ss')#</ns:ShipTimestamp>
<ns:DropoffType>REGULAR_PICKUP</ns:DropoffType>
<ns:PackagingType>YOUR_PACKAGING</ns:PackagingType>
<ns:TotalWeight>
<ns:Units>LB</ns:Units>
<ns:Value>#arguments.pkgWeight#</ns:Value>
</ns:TotalWeight>
<ns:TotalInsuredValue>
<ns:Currency>USD</ns:Currency>
<ns:Amount>#arguments.pkgValue#</ns:Amount>
</ns:TotalInsuredValue>
<ns:Shipper>
<ns:Address>
<ns:StreetLines>#arguments.shipperAddress1#</ns:StreetLines>
<ns:City>#arguments.shipperCity#</ns:City>
<ns:StateOrProvinceCode>#arguments.shipperState#</ns:StateOrProvinceCode>
<ns:PostalCode>#arguments.shipperZip#</ns:PostalCode>
<ns:CountryCode>#arguments.shipperCountry#</ns:CountryCode>
</ns:Address>
</ns:Shipper>
<ns:Recipient>
<ns:Address>
<ns:StreetLines>#arguments.shiptoaddress1#</ns:StreetLines>
<ns:City>#arguments.shiptocity#</ns:City>
<ns:StateOrProvinceCode>#arguments.shiptostate#</ns:StateOrProvinceCode>
<ns:PostalCode>#arguments.shiptozip#</ns:PostalCode>
<ns:CountryCode>#arguments.shiptocountry#</ns:CountryCode>
<ns:Residential>#arguments.shiptoresidential#</ns:Residential>
</ns:Address>
</ns:Recipient>
<ns:RateRequestTypes>LIST</ns:RateRequestTypes>
<ns:PackageCount>1</ns:PackageCount>
<ns:PackageDetail>INDIVIDUAL_PACKAGES</ns:PackageDetail>
<ns:RequestedPackageLineItems>
<ns:SequenceNumber>1</ns:SequenceNumber>
<ns:InsuredValue>
<ns:Currency>USD</ns:Currency>
<ns:Amount>#arguments.pkgValue#</ns:Amount>
</ns:InsuredValue>
<ns:Weight>
<ns:Units>LB</ns:Units>
<ns:Value>#arguments.pkgWeight#</ns:Value>
</ns:Weight>
<cfif arguments.pkgLength GT 0 AND arguments.pkgWidth GT 0 AND arguments.pkgHeight>
<ns:Dimensions>
<ns:Length>#arguments.pkgLength#</ns:Length>
<ns:Width>#arguments.pkgWidth#</ns:Width>
<ns:Height>#arguments.pkgHeight#</ns:Height>
<ns:Units>IN</ns:Units>
</ns:Dimensions>
</cfif>
</ns:RequestedPackageLineItems>
</ns:RequestedShipment>
</ns:RateRequest>
</cfoutput></cfsavecontent>
<cfif arguments.sandbox>
<!--- <cfset fedexUrl = "https://gatewaybeta.fedex.com/xml"> original code --->
<cfset fedexUrl = "https://gatewaybeta.fedex.com:443/xml">
<cfelse>
<!--- <cfset fedexUrl = "https://gateway.fedex.com/xml"> original code --->
<cfset fedexUrl = "https://gateway.fedex.com:443/xml">
</cfif>
<!--- send the request --->
<cfhttp url="#fedexurl#" port="443" method ="POST" throwonerror="yes">
<cfhttpparam name="name" type="XML" value="#XMLPacket#">
</cfhttp>
<cfset xmlFile = XmlParse(CFHTTP.FileContent)>
<!---Build the Struct for Return--->
<cfset err = false>
<cfset fedexReply = StructNew()>
<cfset fedexReply.response = Arraynew(1)>
<!---Did you pass bad info or malformed XML?--->
<cfif not isDefined('xmlFile.Fault')>
<cfloop from="1" to="#arrayLen(xmlfile.RateReply.Notifications)#" index="n">
<cfset fedexReply.response
<cfset fedexReply.response
<cfset fedexReply.response
<cfif fedexReply.response
<cfset err = true>
</cfif>
</cfloop>
<!---Did FedEx reply with an error?--->
<cfif NOT err>
<!--- Extract rates --->
<cfset fedexReply.rate = ArrayNew(1)>
<cfloop from="1" to="#arrayLen(xmlfile.RateReply.RateReplyDetails)#" index="r">
<cfset fedexReply.rate
<cfset fedexReply.rate
<cfset fedexReply.rate
</cfloop>
</cfif>
<cfelse>
<cfset fedexReply.response = ArrayNew(1)>
<cfset fedexReply.response[1] = structNew()>
<cfset fedexReply.response[1].status = "Error">
<cfset fedexReply.response[1].msg = "Please check your code...you most likely have an invalid character in your validation variables">
</cfif>
<cfreturn fedexReply>
</cffunction>
</cfcomponent>
Here's the template that's calling the cfc:
<cfinvoke component="FedexRates_v7" method="getRates" returnvariable="fedex"
shipperAddress1 = "333 Corporate Woods Parkway"
shipperCity = "Vernon Hills"
shipperState = "IL"
shipperZip = "60061"
shiptoAddress1 = "30 Executive Park"
shiptoCity = "Irvine"
shiptoState = "CA"
shiptoZip = "92614"
pkgWeight = "50"
pkgValue = "100"
>
<cfdump var="#fedex#"> <!--- I'm getting the error here: "Authentication Failed" --->
<cfoutput>
<select name="shipping">
<cfloop from="1" to="#arraylen(fedex.rate)#" index="n">
<option value="#fedex.rate
</cfloop>
</select>
</cfoutput>
FedEx Web Services Resource Center: http://www.fedex.com/us/developer/
Copy link to clipboard
Copied
The error message I'm getting is: Authentication Failed
Make sure you supplied your credentials (key, meter number, etcetera). By default, the function passes an empty string. That is probably why you are getting an authentication failure.
Copy link to clipboard
Copied
I did supply my credentials (key, meter number, password) as you can see in the code above under "FedexRates_v7.cfc".
Well, I guess I'm just going to generate a new set of credentials and try it out. BTW, would your "FedexRates_v7.cfc" work with the latest FedEx Web Services version 8????
Thanks.
Copy link to clipboard
Copied
I did supply my credentials (key, meter number, password)
as you can see in the code above under
"FedexRates_v7.cfc".
My bad. I did not even look at the cffunction code. I just assumed it was the same as on google code. I was able to get rates from v7. So yes, there may be a problem with your credentials.
"FedexRates_v7.cfc" work with the latest FedEx Web
Services version 8????
I do not know. Though based on past history, my guess would be no.
Copy link to clipboard
Copied
Hi,
So what do I have to change in FedexRates_v7.cfc to make it work with the latest FedEx Web
Services version 8?
Many thanks in advance.
Copy link to clipboard
Copied
Try this version
http://code.google.com/p/cffedexrates/issues/detail?id=4
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more