Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I create UPS package shipments/pickup requests with PHP? Sample code?

Tags:

php

ups

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?

like image 671
Keith Palmer Jr. Avatar asked Aug 12 '09 16:08

Keith Palmer Jr.


People also ask

What is UPS PHP?

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.

Is UPS shipping API free?

UPS Shipping API [Free Integration and Tracking]

How do I create a UPS shipment?

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.

Does UPS have an API?

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.


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'];
like image 136
arbales Avatar answered Oct 16 '22 05:10

arbales


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 );
like image 23
Scott C Wilson Avatar answered Oct 16 '22 05:10

Scott C Wilson