FedEx Tracking API Integration with PHP

FedEx Tracking API Integration with PHP

PHP
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

// 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
	)
);

 

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.


$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);

 

$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!

Leave a Reply

Your email address will not be published. Required fields are marked *

1 × 5 =

2hats Logic HelpBot