Let’s start the tutorial with this question: “What is Fedex ?”
As Wikipedia explains :

 FedEx Corporation is an American multinational courier delivery services company headquartered in Memphis, Tennessee. The company is known for its overnight shipping service, but also for pioneering a system that could track packages and provide real-time updates on package location (to help in finding lost packages), a feature that has now been implemented by most other carrier services .

In this tutorial you will learn about each portion of Fedex PHP API , the requirements to start and a general comprehension about working with these portions and in the rest you will cover the problem with an example in PHP .

Where do i start ?

If you have never used Fedex API , that would be better to take a look to FedEx Web Services Developer Guide to make better understanding what they are offering and how scalable can be your codes. But if you are lazy like me , you can skip reading their whole PDF document and follow this tutorial to go forward.

Step 1 : Register in FedEx website

Before doing anything and start any programming with Fedex API , we need to have an account in the Fedex website and get access to the developer console page and after that we can prospect our view of development . The registration steps are so simple and i have skipped in this article complete process . But after finishing the registration you will face to a final page as following that your Fedex User ID will appear on the page and also you will receive a confirmation email  of registration in your inbox.

[ Fedex registration confirmation final page ]

Step 2 : Create a test key

The first step is to have a test key for your development box because every transaction in the code needs a key to identify  your identity as a valid user and process your codes according by that . To start making a test key after going to this url you need to enter your information again and accept their terms as provided . After these two easy steps , you will get an email with your test key and related information on your mailbox. Please keep those information for next steps.

Step 3 : Installing Requirements

‌Before you start writing your awesome codes, you need to install a client library of the Fedex API in order to interact with their server using WSDL . I prefer to use a fluid PHP library by JeremyDunn  that makes life easier.  This can be done by git  as following :

$ git clone https://github.com/JeremyDunn/php-fedex-api-wrapper.git

After running the above line in your bash, it creates a new folder php-fedex-api-wrapper in your system and all related stuffs goes there .
The Fedex API consists 13 web services that each web service has its own class namespace. See the official FedEx web service API documentation for a description of these services.

In this article we will work with Ship Service web service and the related functionalities in our code .

 

Step 4 : Dive into the codes

To get starting our process of development , we go forward with example folder inside the api library. It contains some examples of different web services functionalities. Before doing anything we make a copy of credential file with another name in example folder as following :

$ cd php-fedex-api-wrapper/examples/
$ cp example.credentials.php credentials.php

The credentials.php file keeps information of your Account number,Meter number , Key and  password that you need to fill them from step2.

As i said earlier , we gonna work with ship web service in the library .Fortunately this library has provided an example of working with Shipment section of web service that makes our process much easier .
Open the ship.php in the example folder by your IDE and fill these variables same as your package info :

  • $shipperAddress ( Shipper Adress , City ,State ,Postal Code , Country Code)
  • $shipperContact  ( Shipper Company name , Email , shipper name , shipper phone number  )
  • $recipientAddress ( Recipient Adress , City ,State ,Postal Code , Country Code)
  • $recipientContact ( Recipient Company name , Email , shipper name , shipper phone number  )
  • $packageLineItem1 ( Your package information such as Width , Height ,Length, Units, Weight )

When you did your changes on above variables of ship.php file , then your code are ready and you only need to say Voila !!!!

$ php ship.php

Congratulation , your codes are ready and we could write our first Fedex PHP code easily .

 

Show CommentsClose Comments

3 Comments

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.