{note} You're browsing the documentation for an old version of laravel-ups. Consider upgrading your project to v2. Check your version with the following command:

composer show rawilk/laravel-ups

Like the name suggests, the tracking api allows you to track your shipments via the api.

The most basic usage of the api involves providing a tracking number for a package or shipment. Please consult the developer documentation before using.

use Rawilk\Ups\Apis\Tracking\Tracking;

$response = (new Tracking)
    ->usingTrackingNumber('YOUR TRACKING NUMBER')

// On a successful request, the "shipment" attribute will return an instance of Rawilk/Ups/Entity/Shipment/Shipment.

When using a Shipment instance created from the package's tracking response, there are a few pieces of information you can retrieve from it:

// Returns a Carbon date instance of the date the shipment was picked up
// returns null if not picked up yet

// Returns true if the shipment has been picked up

// Returns an instance of Rawilk/Ups/Entity/Shipment/ReferenceNumber if there is a reference number on the shipment.
// May return an array of instances if more than one reference number is found.

// Returns a collection of Rawilk/Ups/Entity/Shipment/Package instances.

// Get the first package in the shipment...
$package = $response->shipment->packages->first();

// Returns a collection of tracking activities for the package (Rawilk/Ups/Entity/Activity/Activity)

// Returns true if the package has an activity with a "delivery" code on it.

// If the package has an activity that was "delivered" and there as a signature, it will return
// the name of the person that signed.

// If the package has any activities that have a "pickup" code, this will return true.
// Note: Depending on your request options, you may not see any activities marked as "pickup".

For each package, there can be multiple activities recorded by UPS. Each of them are converted to an Rawilk/Ups/Entity/Activity/Activity instance when a response is read from the api. Here is some of the information you can get from an activity.

// Returns a Carbon instance of the parsed date/time of the activity.

// Some other date/times available

// Package activity status container. Useful in determining what kind of activity it is.

// Will return a code of the status of the activity.
// 'D' => Delivered
// 'P' => Pickup

// Name of person who signed for package.

// Convenience method for determining if it is a "pickup" activity.

// Convenience method for determining if it is a "delivered" activity.

UPS gives you the ability to track a package or shipment by using a reference number. Reference numbers can be a purchase order number, job number, etc. Reference Number is supplied when generating a shipment.

(new Tracking)->usingReferenceNumber('Your reference number');

Using your shipper number allows you to further limit the results to your account:

(new Tracking)->usingShipperNumber('Your shipper number');

Allows for optional processing. Default is to include "All activity". Here are a couple ways you can specify the request option:

$api = new Tracking;

// Via the "requestOption" method:

// Via a convenience method:
$api->allActivity(); // TrackingOptions::ALL_ACTIVITY
$api->lastActivity(); // TrackingOptions::LAST_ACTIVITY

Note: There are more options available, found in Rawilk/Ups/Apis/Tracking/TrackingOptions. We've just added convenience methods for our common use cases.

The most common errors you'll probably run into are for no tracking information available or invalid tracking numbers:

When a shipment is created, its tracking information will not be available right away. It's best to wait at least 10 minutes before attempting to retrieve any tracking information on it.

Here's how you can check for this error specifically:

$response = (new Tracking)
    ->usingTrackingNumber('YOUR TRACKING NUMBER')

if ($response->noTrackingInformationAvailable()) {
    // do something
    echo $response->error_description;

When an invalid tracking number is used, ups will return an error. Here's how you can check for it:

$response = (new Tracking)
    ->usingTrackingNumber('YOUR TRACKING NUMBER')

if ($response->invalidTrackingNumber()) {
    // do something
    echo $response->error_description;

You can check for other errors by using $response->failed():

$response = (new Tracking)
    ->usingTrackingNumber('YOUR TRACKING NUMBER')

if ($response->failed()) {
    // do something
    echo $response->error_code; // E.g. 151018 for invalid tracking number
    echo $response->error_description;
Caught a mistake? Suggest an edit on GitHub