ParcelForce expressLink API Integration
Having recently worked on integrating ParcelForce’s expressLink web service for a client there appeared to be very little online about how to work with this service using PHP. The following code shows how we set this up using the NuSOAP library. Note the below uses the expresslink test server.
If you need a development team for a project involving ParcelForce’s API then please Contact Us for a quotation.
Update: Previously the WSDL was loaded remotely from http://expresslink-test.parcelforce.net/ws/?wsdl however ParcelForce now require the WSDL to be hosted locally. This file is supplied by ParcelForce
Creating a shipment
<!--?php $client = new nusoap_client('ShipService_v5.wsdl', true); $params = array( "Authentication" =--> array( "UserName"=>"xxxxx", "Password"=>"xxxxx" ), "RequestedShipment" => array( "ShipmentType"=>"DELIVERY", "ContractNumber"=>"xxxxx", "ServiceCode"=>"SUP", "RecipientContact"=>array( "BusinessName"=>"xxxxx" ), "RecipientAddress"=>array( "AddressLine1"=>"xxxxx", "Town"=>"xxxxx", "Postcode"=>"xxxxx", "Country"=>"xxxxx" ), "ShippingDate"=>"xxxx-xx-xx", "TotalNumberOfParcels"=>"x", ) ); $response = $client->call('createShipment', array('CreateShipmentRequest' => $params)); ?>
The parameters in the $params array are all of the essential parameters that are required to be passed, on top of these there are numerous other optional ones. Replace the ‘x’ values with the relevant information. Username and password should have been supplied to you when signing up to expressLink. ServiceCode’s are available in the expressLink documentation, SUP in this case refers to their express 48 hour service. If successful the $response array variable should contain a key with the shipment number created called:
$response['CompletedShipmentInfo']['CompletedShipments']['CompletedShipment']['ShipmentNumber']
Creating a printable label
<!--?php $client = new nusoap_client('http://expresslink-test.parcelforce.net/ws/?wsdl', true); $params = array( "Authentication" =--> array( "UserName"=>"xxxxx", "Password"=>"xxxxx" ), "ShipmentNumber"=>"xxxxx" ); $response = $client->call('printLabel', array('PrintLabelRequest' => $params)); $pdf = base64_decode($response['Label']['Data']); ?>
The variable $pdf can then be saved to a PDF file or output to a browser
Note that the above code is for illustration purposes only and doesn’t contain any validation or checking for error response codes.



