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?
-
1UPS Noobs may wish to start with this post first: https://stackoverflow.com/questions/43514051/ups-shipping-tutorial-php/ – Scott C Wilson Dec 21 '17 at 17:22
2 Answers
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'];

- 5,466
- 4
- 33
- 40
-
Thanks, I had looked at that but hadn't noticed that the latest svn builds have shipping support. – Keith Palmer Jr. Aug 12 '09 at 17:37
-
I didn't realize it at first either, I was actually pretty relieved for the time-saving. – arbales Aug 15 '09 at 06:23
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 );

- 19,102
- 10
- 61
- 83