How to Create Fedex Multiple Package Shipment Label using API Call in PHP

Fedex Multiple Package Shipment Label using API Call in PHP
In our previous post explained how to create Fedex shipping label using PHP programming language. In this post we explain fedex multiple package shipment label process. By default Fedex allow maximum 150 pound weight limit for one box shipment. If your order exceed shipment weight limit, than Fedex divide package weight as limit wise.

Generate Fedex Multiple Package Shipment Label

In this case one Master Tracking label id is creating for first package, you need to send this master tracking id to child package for create label for each package. You can also check our previous Fedex shipping label code post for single package. Lets check the below PHP code to create Fedex multiple package labels.

<?php

$path_to_wsdl = "./ShipService_v19.wsdl";

define('SHIP_MASTERLABEL', 'shipmasterlabel.pdf');
define('SHIP_CHILDLABEL_1', 'shipchildlabel_1.pdf');
define('SHIP_CODMASTERLABEL', 'CODmasterlabel.pdf');
define('SHIP_CODCHILDLABEL_1', 'CODchildlabel_1.pdf');

ini_set("soap.wsdl_cache_enabled", "0");

$client = new SoapClient($path_to_wsdl, array('trace' => 1));

$masterRequest['WebAuthenticationDetail'] = array(
	'ParentCredential' => array(
		'Key' => 'Paste Your API Key Here', 
		'Password' => 'Paste Your Password Here'
	)
);

$masterRequest['ClientDetail'] = array(
	'AccountNumber' => '51*****5', 
	'MeterNumber' => '1******8'
);
$masterRequest['TransactionDetail'] = array('CustomerTransactionId' => '*** Ground Domestic MPS Shipping Request - Master using PHP 

***');
$masterRequest['Version'] = array(
	'ServiceId' => 'ship', 
	'Major' => '19', 
	'Intermediate' => '0', 
	'Minor' => '0'
);
$masterRequest['RequestedShipment'] = array(
	'ShipTimestamp' => date('c'),
	'DropoffType' => 'BUSINESS_SERVICE_CENTER',
	'ServiceType' => 'GROUND_HOME_DELIVERY',
	'PackagingType' => 'YOUR_PACKAGING',
	'Shipper' => array(
		'Contact' => array(
			'PersonName' => 'Sender Name',
			'CompanyName' => 'example.com',
			'PhoneNumber' => '800-0987-6489'
		),
		'Address' => array(
			'StreetLines' => array('1300 Basswood Road'),
			'City' => 'Austin',
			'StateOrProvinceCode' => 'TX',
			'PostalCode' => '73301',
			'CountryCode' => 'US'
		)
	),
	'Recipient' => array(
		'Contact' => array(
			'PersonName' => 'Recipient Name',
			'CompanyName' => 'example',
			'PhoneNumber' => '1234567890'
		),
		'Address' => array(
			'StreetLines' => array('32 wall street albany'),
			'City' => 'Herndon',
			'StateOrProvinceCode' => 'VA',
			'PostalCode' => '20171',
			'CountryCode' => 'US',
			'Residential' => true
		)
	),
	
	'LabelSpecification' => array(
		'LabelFormatType' => 'COMMON2D', 
		'ImageType' => 'PDF', 
		'LabelStockType' => 'PAPER_7X4.75',
		), 
	'PackageCount' => 2,
	'RateRequestTypes' => 'LIST',
	'RequestedPackageLineItems' => array(
		'0' => array(
		'SequenceNumber'=>1,
		'GroupPackageCount'=>1,
		'InsuredValue' => array(
			'Amount' => 100.00, 
			'Currency' => 'USD'
		),
		'Weight' => array(
			'Value' => 70.0,
			'Units' => 'LB'
		),
		'Dimensions' => array(
			'Length' => 20,
			'Width' => 10,
			'Height' => 10,
			'Units' => 'IN'
		),
		'CustomerReferences' => array(
			'0' => array(
				'CustomerReferenceType' => 'CUSTOMER_REFERENCE', 
				'Value' => 'GR4567892'
			),
			'1' => array(
				'CustomerReferenceType' => 'INVOICE_NUMBER', 
				'Value' => 'INV4567892'
			),
			'2' => array(
				'CustomerReferenceType' => 'P_O_NUMBER', 
				'Value' => 'PO4567892'
			)
		)
	)
);


$masterResponse = $client->processShipment($masterRequest); 

$fp = fopen(SHIP_CODMASTERLABEL, 'wb');   
fwrite($fp, $masterResponse->CompletedShipmentDetail->CompletedPackageDetails->CodReturnDetail->Label->Parts->Image);
fclose($fp);
echo '<a href="./'.SHIP_CODMASTERLABEL.'">'.SHIP_CODMASTERLABEL.'</a> was generated.'.Newline;
	
$fp = fopen(SHIP_MASTERLABEL, 'wb');   
fwrite($fp, ($masterResponse->CompletedShipmentDetail->CompletedPackageDetails->Label->Parts->Image));
fclose($fp);
echo '<a href="./'.SHIP_MASTERLABEL.'">'.SHIP_MASTERLABEL.'</a> was generated. Processing package# 1 ...'; 
echo "<br>";
	    
// child label request
	    
$childRequest['WebAuthenticationDetail'] = 
                                      array(
						'ParentCredential' => array(
							'Key' => 'Paste Your API Key Here', 
							'Password' => 'Paste Your Password Here'
						)
	    );
	    
	    $childRequest['ClientDetail'] = array(
						'AccountNumber' => '51******85', 
						'MeterNumber' => '11*****08'
	    );
	    $childRequest['TransactionDetail'] = array('CustomerTransactionId' => '*** Ground Domestic MPS Shipping Request - Child 

using PHP ***');
	    $childRequest['Version'] = array(
	    	'ServiceId' => 'ship', 
	    	'Major' => '19', 
	    	'Intermediate' => '0', 
	    	'Minor' => '0'
	    );
	    $childRequest['RequestedShipment'] = array(
	    	'ShipTimestamp' => date('c'),
			'DropoffType' => 'DROP_BOX',
			'ServiceType' => 'FEDEX_GROUND', // valid values STANDARD_OVERNIGHT, PRIORITY_OVERNIGHT, FEDEX_GROUND, ...
			'PackagingType' => 'YOUR_PACKAGING', // valid values FEDEX_BOX, FEDEX_PAK, FEDEX_TUBE, YOUR_PACKAGING, ...
				'Shipper' => array(
		'Contact' => array(
			'PersonName' => 'Sender Name',
			'CompanyName' => 'example.com',
			'PhoneNumber' => '800-0987-6489'
		),
		'Address' => array(
			'StreetLines' => array('1300 Basswood Road'),
			'City' => 'Austin',
			'StateOrProvinceCode' => 'TX',
			'PostalCode' => '73301',
			'CountryCode' => 'US'
		)
	),
	'Recipient' => array(
		'Contact' => array(
			'PersonName' => 'Recipient Name',
			'CompanyName' => 'example',
			'PhoneNumber' => '1234567890'
		),
		'Address' => array(
			'StreetLines' => array('32 wall street albany'),
			'City' => 'Herndon',
			'StateOrProvinceCode' => 'VA',
			'PostalCode' => '20171',
			'CountryCode' => 'US',
			'Residential' => true
		)
	),
				'LabelSpecification' => array(
					'LabelFormatType' => 'COMMON2D', // valid values COMMON2D, LABEL_DATA_ONLY
					'ImageType' => 'PDF',  // valid values DPL, EPL2, PDF, ZPLII and PNG
					'LabelStockType' => 'PAPER_7X4.75',
					), 
			'MasterTrackingId' => $masterResponse->CompletedShipmentDetail->MasterTrackingId,
			'RateRequestTypes' => 'LIST', // valid values ACCOUNT and LIST
			'PackageCount' => 2,
			'RequestedPackageLineItems' => array(
									'0' => array(
							'SequenceNumber'=>2,
							'GroupPackageCount'=>1,
							'InsuredValue' => array(
								'Amount' => 75.00, 
								'Currency' => 'USD'
							),
							'Weight' => array(
								'Value' => 15.0,
								'Units' => 'LB'
							),
							'Dimensions' => array(
								'Length' => 15,
								'Width' => 10,
								'Height' => 10,
								'Units' => 'IN'
							),
							'CustomerReferences' => array(
								'0' => array(
									'CustomerReferenceType' => 'CUSTOMER_REFERENCE', 
									'Value' => 'GR4567892'
								),
								'1' => array(
									'CustomerReferenceType' => 'INVOICE_NUMBER', 
									'Value' => 'INV4567892'
								),
								'2' => array(
									'CustomerReferenceType' => 'P_O_NUMBER', 
									'Value' => 'PO4567892'
								)
							)
						)
			)
	    );                                                                                                                         

                                                                                                                                       
	    $childResponse = $client->processShipment($childRequest);

$child_tracking_number = $childResponse->CompletedShipmentDetail->CompletedPackageDetails->TrackingIds-

>TrackingNumber;
	
	        $fp = fopen(SHIP_CODCHILDLABEL_1, 'wb');   
	        fwrite($fp, $childResponse->CompletedShipmentDetail->CompletedPackageDetails->CodReturnDetail->Label->Parts->Image);
	        fclose($fp);
	        echo '<a href="./'.SHIP_CODCHILDLABEL_1.'">'.SHIP_CODCHILDLABEL_1.'</a> was generated.'.Newline;
	       
	        $fp = fopen(SHIP_CHILDLABEL_1, 'wb');   
	        fwrite($fp, ($childResponse->CompletedShipmentDetail->CompletedPackageDetails->Label->Parts->Image));
	        fclose($fp);
	        echo '<a href="./'.SHIP_CHILDLABEL_1.'">'.SHIP_CHILDLABEL_1.'</a> was generated';  
	        
	        $imagick = new Imagick();
		$imagick->readImage('./shipchildlabel_1.pdf'); // set label path here
		$imagick->writeImages('converted.jpg', false); 



?>

As you see in above code, first master package label is created and pass master tracking id to child package api request. Using this way you can create Fedex Label for Multiple Package Shipments.

Similar Posts

3 Comments

  1. Greetings of the Day,
    Hi, we are using FedEX services with SOAP API for creating the shipping label, but we want to switch with Rest API, if you have the documentation in Rest API, Could you share the documentation with me?
    Please share on [email protected]

Leave a Reply

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