Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help sending/getting Feedback from FedEx via Perl Script 2

Status
Not open for further replies.

DR4296

Technical User
Jan 4, 2001
3
US
Greetings All!

I've been setting up a Perl shopping cart for a friend of mine who just opened his own retail store.

My friend wants to use FedEx as a shipper... nobody else.

I checked out FedEx's site and found that most of the API's require a Windows hosting platform. Well, I've got his site out on Unix, of course.

The only other option FedEx offers is that you can call a particular URL, with parameters added on, in order to look up rate quotes, delivery times, tracking, etc. Here's a sample:



This URL triggers an executable over on FedEx's servers and kicks back a web-page that looks like this:


<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0 Frameset//EN&quot; &quot;<HTML>
<!--#nossi-->
<HEAD>
<TITLE>FedEx Ground Rate Calculation Reply</TITLE>
</HEAD>
<BODY BGCOLOR=&quot;#FFFFFF&quot; LINK=&quot;#DE5208&quot; VLINK=&quot;#9425E6&quot; ALINK=&quot;#000000&quot;>
<font size=&quot;5&quot; face=&quot;arial, courier new&quot;>
<i><b>FedEx Ground Rate Calculation</b></i>
</font>
<font size=&quot;-1&quot; face=&quot;arial, courier new&quot;>
<!-- Begin Reply Message -->
<table border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;5&quot; width=&quot;440&quot;>
<TR><TD ALIGN=&quot;LEFT&quot; VALIGN=&quot;TOP&quot; COLSPAN=&quot;4&quot;>
<!Service>U.S. Domestic FedEx Ground Package<!/Service>
<!Origin>44429<!/Origin>
<!Destination>64050<!/Destination>
<!Zone>5<!/Zone>
<!TransitTime>3<!/TransitTime>
<!Weight>50<!/Weight>
<!BillWeight>50<!/BillWeight>
<!WeightUnit>LBS<!/WeightUnit>
<!BaseRate>15.47<!/BaseRate>
<!TotalCharges>15.47<!/TotalCharges>
</TD></TR>
</table>
<!-- End Reply Message -->
</font>
</BODY>
</HTML>


What I'd like to know is... (and I'll admit that I'm not a formally-trained Perl programmer... I just learned by tinkering)....:

1) I know I can &quot;build&quot; the request URL with the proper parameters from the cart, but how can I &quot;call&quot; the URL from within the cart/Perl script itself ?

2) And, can I somehow &quot;capture&quot; the response sent from the FedEx servers/exe... sort through the output... and just &quot;take out&quot; the info from the necessary fields that I need (rate quotes mostly), so as to plug them into the HTML output of the shopping cart properly ??

Thanks !

-= Dave Raasch =-
Independence, MO
 
i think you can do all that quite easily with the LWP module but as i haven't used that before and am in a bit of a rush i'm afraid i can't help more than that
(you can get the lwp module from )

good luck
 
Here is a short version of retrieving a web page usin LWP::Simple. You would want to build your cart/item specific URL to get.

Code:
#!/usr/local/bin/perl
use LWP::Simple;
$url='[URL unfurl="true"]http://grd.fedex.com/cgi-bin/rrr2010.exe?func=Rate&amp;;Screen=Ground[/URL]
    &amp;OriginZip=44429&amp;OriginCountryCode=US&amp;DestZip=64050&amp;DestCountryCode=US
    &amp;Weight=50';

# pull the HTML of the requested page into $content
$content = get($url);

# print that content to your browser
print &quot;Content-type: text/html\n\n&quot;;
print &quot;$content&quot;;


With the page pulled into $content, you can pattern match the items you want to catch.
If you want to catch <!TotalCharges>15.47<!/TotalCharges>,

Code:
# looking for <!TotalCharges>some_digits dot some_digits<
# catching &quot;some_digits dot some_digits&quot;, (\d+\.\d+), in parens puts them in $1
$content =~ /<!TotalCharges>(\d+\.\d+)</s;
$shipping_cost = $1; # the portion of the match in parens.

I have not run this, but it should be pretty close to functional.

'hope this helps.....




keep the rudder amid ship and beware the odd typo
 
That XML in there is your savior. That makes it very easy to parse out like goBoating suggested.
Sincerely,

Tom Anderson
CEO, Order amid Chaos, Inc.
 
A thousand thanks to you all !

Thanks to frequent checking on this board, I discovered &quot;aljc's&quot; post on the LWP module early.

I'd been experimenting with it, using Google to lookup possible examples when I had problems. The only problem I had left was... I have a tendency to get stuck on the pattern-matching stuff.... what character-combos mean what.

So, coming back here and finding &quot;GoBoating&quot;'s post was like finding the last piece of the puzzle !!

Thanks !

You shortened my work-time considerably and have introduced me to a powerful, fun function !

P.S. By the way, I also ended up over at CPAN and discovered modules there for UPS and Fed Ex shipping. However, the FedEx one there uses FedEx's more-advanced API interface. It requires another module... and when I tried to install that module, I didn't have enough permissions on my web-server. So I gave up and went back to the above method.

THANK YOU !!!!!!!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top