I am doing a fairly large implementation using the exposed APIs of all 4 major shippers. I’ve posted a few notes on USPS, and I’ve been using UPS for so long it almost seems to make perfect sense.
So, while I have to applaud FedEx for the granularity and versatility of the API they have exposed, it has caused me severe headaches due to the PHP SimpleXML issues it brings up with SOAP envelopes — particularly nested soap envelopes.
Long story short, the jist of this post is to help others deal with the responses they receive from the FedEx servers (if, like me, their pre-packaged methods do not implement tidily into your application structure).
Here is a sample response of a rate request (NOTE: this is a “Warning” response, only here for demo purposes):
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<env:Header xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" />
<env:Body xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<v8:RateReply xmlns:v8="http://fedex.com/ws/rate/v8">
<v8:HighestSeverity>WARNING</v8:HighestSeverity>
<v8:Notifications>
<v8:Severity>WARNING</v8:Severity>
<v8:Source>crs</v8:Source>
<v8:Code>556</v8:Code>
<v8:Message>There are no valid services available. </v8:Message>
<v8:LocalizedMessage>There are no valid services available. </v8:LocalizedMessage>
</v8:Notifications>
<v8:TransactionDetail xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
<v8:CustomerTransactionId>TC05_Rate_Package_Groups_POS</v8:CustomerTransactionId>
</v8:TransactionDetail>
<v8:Version xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
<v8:ServiceId>crs</v8:ServiceId>
<v8:Major>8</v8:Major>
<v8:Intermediate>0</v8:Intermediate>
<v8:Minor>0</v8:Minor>
</v8:Version>
</v8:RateReply>
</env:Body>
</soapenv:Envelope>
There are lots of ways you might envision accessing that precious “RateReply” tag, but to keep it simple and avoid inferences, you get to it like this:
$xml = simplexml_load_string ($xml_from_above);
$xml->children(‘http://schemas.xmlsoap.org/soap/envelope/’)->Body->children(‘http://fedex.com/ws/rate/v8′)->RateReply;
I do suppose this is obvious enough, but believe me, the nuances that can throw it off can still cause you to inadvertently lose ridiculous amounts of time on it.
Furthermore, if you prefer to do direct PHP cURL XML calls (which you probably do given that you’re reading this), you’ll find that FedEx is not terribly interested in your type of programmer. To find a simple sample XML call, you’ll have a tough time (although I managed to find it in the WSDL downloadable ZIP). However, this is a very basic call. To add additional data (such as the exotic field that apparently no one would ever think to use — “InsuredValue”) — this field has the form (EXACTLY, stuff in brackets is what can be changed) “<InsuredValue><Currency>[currencytype]</Currency><Amount>[float]</Amount></InsuredValue>”
The “InsuredValue” node/field must go immediately before the “Weight” node in the “RequestedPackageLineItems” node. (This of course reference FedEx API v8 — things may be different in future releases.)
Customer Review – RockAuto.com
I have a 1990 Ford F-250 pickup truck that is pretty much a beater, but it’s a damn workhorse. I love the truck, but I am always fixing things on it.
Pretty soon it will be a 2010 model. Anyway, recently I was hauling a load of stone, and the driver’s side rear spring hanger’s rivets broke lose and bent the hanger away from the frame. On closer inspection, the rear hangers on both side are quite rusted, and they should have been replaced years ago.
I checked around local junk yards, and most of them wanted anywhere from $40 to $60 a piece for replacement hangers, or they just didn’t have them, or only had 1 (and I’m replacing both). So, being employed in a field directly tied to the internet, I checked Google. If any of you have ever searched for car parts online, you know that RockAuto.com carries pretty much everything you can find, and their prices are very reasonable (usually the cheapest outright on Google Shopping).
Lo and behold, they have my part — more importantly, they have at least 2 — new — for $20 ea. plus $10 shipping. Mondary morning (May 24, 2010) I placed the order. When I came home from work on Tuesday, the parts had arrived.
With the recent string of crappy companies I’ve been dealing with in terms of purchasing online, RockAuto.com is the most amazing breath of fresh air ever (pardon the poetical slathering, but seriously … they are awesome.) Do not hesitate to buy from them!
Posted in Commentary, Personal, Reviews