2Hats . 5 minutes
December 5, 2019

FedEx Tracking API Integration with PHP

FedEx is an American courier delivery services company. By using FedEx Tracking API, we can get real-time tracking information for FedEx Express, FedEx Ground, FedEx SmartPost, FedEx Home Delivery, FedEx Express Freight, FedEx Freight, and FedEx Custom Critical shipments.

 

FedEx Web Services Environments

FedEx API has 2 environments. Testing and Production. 

The FedEx Web Services Testing Environment is a functional, full-runtime environment ideal for testing your web services solutions. Although good for confirming functionality, the Testing Environment should not be used for stress testing. It is recommended that developers test to ensure that their code operates as desired. You can request to test credentials from FedEx Test System Access

 

Once the testing is completed then we need to move the web Services to Production. FedEx Web Service moving to production will need a new set of credentials that will replace the test credentials currently in their application. Credentials include Meter Number, Authentication Key, and Password. You can request production credentials from FedEx Web Services Production Access

 

For connecting to FedEx Tracking API, we need the following details

  • WSDL file
  • FedEx Authentication Key
  • FedEx API Password
  • Account Number 
  • Meter Number

First, create an account on fedex.com and login. You can download the WSDL file from FedEx Documentation and Downloads page under Track Shipment tab

 

 

and all other details will get from the success page of the Requesting Credentials or they will send an mail with the details is shown below.

 

 

Building Request Array to Send FedEx

[code lang=”php”]// Build Authentication
$request[‘WebAuthenticationDetail’] = array(
‘UserCredential’ => array(
‘Key’ => $key //Replace it with FedEx Key,
‘Password’ => $password //Replace it with FedEx API Password
)
);

//Build Client Detail
$request[‘ClientDetail’] = array(
‘AccountNumber’ => $accountNo //Replace it with Account Number,
‘MeterNumber’ => $meterNo //Replace it with Meter Number
);

// Build Customer Transaction Id
$request[‘TransactionDetail’] = array(
‘CustomerTransactionId’ => ‘API request by using PHP’
);

// Build API Version info
$request[‘Version’] = array(
‘ServiceId’ => ‘trck’,
‘Major’ => 18, // You can change it based on you using api version
‘Intermediate’ => 0, // You can change it based on you using api version
‘Minor’ => 0 // You can change it based on you using api version
);

// Build Tracking Number info
$request[‘SelectionDetails’] = array(
‘PackageIdentifier’ => array(
‘Type’ => ‘TRACKING_NUMBER_OR_DOORTAG’,
‘Value’ => $id //Replace it with FedEx tracking number
)
);

[/code]

 

Sending Request To FedEx

Before sending request you need to ensure that Soap client is enabled on the server in which you are executing the application.

[code lang=”php”]

$wsdlPath = ‘TrackService_v18.wsdl’;
$endPoint = ‘https://wsbeta.fedex.com:443/web-services’; //You will get it when requesting to FedEx key. It might change based on the API Environments

$client = new SoapClient($wsdlPath, array(‘trace’ => true));
$client->__setLocation($endPoint);

$apiResponse = $client->track($request);

[/code]

 

$apiResponsevariable contains the detailed tracking details of the provided tracking number. You can process the response based on your requirement. !!

API Response Example :

Just look at the API response data, which contains everything related to the FedEx shipment tracking.  Some of the most useful response elements are

  • HighestSeverity

    If you want to check whether the API request is a success or not, then you can check this element value. These elements of valid values are FAILURE, ERROR, WARNING, NOTE, and SUCCESS

  • Notifications

    This element contains a detailed description of the API request status. This also includes the severity of the notification, which indicates success or failure or some other information about the request.

  • CompletedTrackDetails

    This contains detailed tracking information.

  • CompletedTrackDetails/TrackDetails

    This element contains detailed information about the requested package.

  • CompletedTrackDetails/TrackDetails/Notification

    This element contains the success or error messages while taking the shipment tracking details. If we provide a valid tracking number then it will be a success and if we provide an invalid tracking number it will be an error.

  • CompletedTrackDetails/TrackDetails/TrackingNumber

    API requested the tracking number

  • CompletedTrackDetails/TrackDetails/PackageWeight

    The weight of the tracking package

  • CompletedTrackDetails/TrackDetails/StatusDetails

    Specify details about the status of the shipment being tracked.

  • CompletedTrackDetails/TrackDetails/StatusDetails/Code

    A code that identifies the current status of the shipment

  • CompletedTrackDetails/TrackDetails/StatusDetails/Description

    A description of the current status of the shipment

  • CompletedTrackDetails/TrackDetails/StatusDetails/Location

    Address details related to the current status. Valid values are City, State, and Country.

Conclusion

FedEx Tracking API offers real-time info for various shipments. Use Testing/Production environments accordingly. Connect with a WSDL file, keys, account/meter numbers. Build a request with authentication, client, ID, version, and tracking details. Enable Soap client before sending. The response includes success/failure status, detailed descriptions, and package info like weight, current status, and location. Master the API to empower your app and improve user experience!

blog
Greetings! I'm Aneesh Sreedharan, CEO of 2Hats Logic Solutions. At 2Hats Logic Solutions, we are dedicated to providing technical expertise and resolving your concerns in the world of technology. Our blog page serves as a resource where we share insights and experiences, offering valuable perspectives on your queries.
Aneesh ceo
Aneesh Sreedharan
Founder & CEO, 2Hats Logic Solutions
Subscribe to our Newsletter
Arsha Contact

    Stay In The Loop!

    Subscribe to our newsletter and learn about the latest digital trends.