I know that UPS has some APIs they make available for doing shipping calculations. Is it possible to create a shipment and PDF shipping label using the UPS APIs with PHP? Does anyone have any working sample code?
The php-ups-api is a library for accessing the UPS APIs from PHP code. APIs currently covered by the library are UPS Quantum View, UPS Tracking, UPS Shipping, UPS Rating, and UPS Time in Transit.
UPS Shipping API [Free Integration and Tracking]
At the top of UPS.com, select "Create a Shipment" from the Shipping tab. Enter your name and address in the “Ship From” section, then the name and address of the recipient in the “Ship To” section.
The UPS Developer Kit offers flexibility in integrating UPS functionality directly into your business systems and e-commerce websites. UPS offers 14 functionalities via APIs that allow you to improve business process efficiencies and enhance your customers' Web experience.
I recently performed an integration using ups-php.
The project seems to have advanced much since then, and supports the most common actions (Rate, Track, Ship, Void) in the development version. It's not finished software, but it's easy to use and build on if required.
The class can be used to get shipping labels and you specify formats and print methods inside the upsShip class. The labels are returned inside the XML response in base64 GIF for you to print out/save.
//Response from UPS
$label = $responseArray['ShipmentAcceptResponse']['ShipmentResults']['PackageResults']['LabelImage']['GraphicImage']['VALUE'];
An integration I have used successfully to print UPS shipping labels is https://github.com/gabrielbull/php-ups-api. If you refer to the https://github.com/gabrielbull/php-ups-api#shipping-class example, once you have successfully made the $api->accept($confirm->ShipmentDigest)
call, the next steps to get the label are:
$base64_string = $accept->PackageResults->LabelImage->GraphicImage;
$ifp = fopen( "foo.gif", 'wb' );
fwrite( $ifp, base64_decode( $base64_string) );
fclose( $ifp );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With