6

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?

Keith Palmer Jr.
  • 27,666
  • 16
  • 68
  • 105
  • 1
    UPS 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 Answers2

3

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'];
arbales
  • 5,466
  • 4
  • 33
  • 40
1

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 );
Scott C Wilson
  • 19,102
  • 10
  • 61
  • 83