×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Help sending/getting Feedback from FedEx via Perl Script
2

Help sending/getting Feedback from FedEx via Perl Script

Help sending/getting Feedback from FedEx via Perl Script

(OP)
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:

http://grd.fedex.com/cgi-bin/rrr2010.exe?func=Rate&;Screen=Ground&OriginZip=44429&OriginCountryCode=US&DestZip=64050&DestCountryCode=US&Weight=50


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


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Frameset//EN" "http://www.w3.org/TR/PR-html40/frameset.dtd";>
<HTML>
<!--#nossi-->
<HEAD>
<TITLE>FedEx Ground Rate Calculation Reply</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" LINK="#DE5208" VLINK="#9425E6" ALINK="#000000">
<font size="5" face="arial, courier new">
<i><b>FedEx Ground Rate Calculation</b></i>
</font>
<font size="-1" face="arial, courier new">
<!-- Begin Reply Message -->
<table border="0" cellpadding="0" cellspacing="5" width="440">
<TR><TD ALIGN="LEFT" VALIGN="TOP" COLSPAN="4">
<!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 "build" the request URL with the proper parameters from the cart, but how can I "call" the URL from within the cart/Perl script itself ?

2)  And, can I somehow "capture" the response sent from the FedEx servers/exe... sort through the output... and just "take out" 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



RE: Help sending/getting Feedback from FedEx via Perl Script

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 http://www.CPAN.org )

good luck

RE: Help sending/getting Feedback from FedEx via Perl Script

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.


#!/usr/local/bin/perl
use LWP::Simple;
$url='&#104;ttp://grd.fedex.com/cgi-bin/rrr2010.exe?func=Rate&;Screen=Ground
    &OriginZip=44429&OriginCountryCode=US&DestZip=64050&DestCountryCode=US
    &Weight=50';

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

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



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


# looking for <!TotalCharges>some_digits dot some_digits<
# catching "some_digits dot some_digits", (\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

RE: Help sending/getting Feedback from FedEx via Perl Script

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.
http://www.oac-design.com

RE: Help sending/getting Feedback from FedEx via Perl Script

(OP)
A thousand thanks to you all !

Thanks to frequent checking on this board, I discovered "aljc's" 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 "GoBoating"'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 !!!!!!!!!

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close