Skip to content

Latest commit

 

History

History
123 lines (84 loc) · 3.22 KB

royal-mail-tracking-api-php.md

File metadata and controls

123 lines (84 loc) · 3.22 KB

Royal Mail Tracking API - PHP

Use PHP to track Royal Mail shipments with Royal Mail Tracking API.

Features

  • Real-time Royal Mail tracking.
  • Batch Royal Mail tracking.
  • Other features to manage your Royal Mail tracking.

Installation

Installation is easy:

$ composer require trackingmore/trackingmore-sdk-php

Quick Start

Get the API key:

To use this API, you need to generate your API key.

  • Click here to access TrackingMore admin.
  • Go to the "Developer" section.

  • Click "Generate API Key".

  • Give a name to your API key, and click "Save" .

Then, start to track your Royal Mail shipments.

Usage

Create a tracking (Real-time tracking):

  require('vendor/autoload.php');

  use Trackingmore\TrackingMoreException;
  use TrackingMore\Trackings;
    
  $key = 'your api key';
  $response = null;
  $trackings = new Trackings($key);
  
  try {
    $params = ['tracking_number'=>'RF423511785GB','courier_code'=>'royal-mail'];
    $response = $trackings->createTracking($params);
  } catch (TrackingMoreException $e) {
    echo $e->getMessage();
  }

  print_r($response);

Create trackings (Max. 40 tracking numbers create in one call):

    require('vendor/autoload.php');

    use Trackingmore\TrackingMoreException;
    use TrackingMore\Trackings;
    
    $key = 'your api key';
    $response = null;
    $trackings = new Trackings($key);
    
    try {
        $params = [
            ['tracking_number'=>'KL698957554GB','courier_code'=>'royal-mail'],
            ['tracking_number'=>'FL356951328GB','courier_code'=>'royal-mail']
        ];
        $response = $trackings->batchCreateTrackings($params);
    } catch (TrackingMoreException $e) {
        echo $e->getMessage();
    }
    
    print_r($response);

Get status of the shipment:

require('vendor/autoload.php');

use Trackingmore\TrackingMoreException;
use TrackingMore\Trackings;

$key = 'your api key';
$response = null;
$trackings = new Trackings($key);

try {
    $params = ['courier_code'=>'royal-mail','created_date_min'=>'2023-08-23T06:00:00+00:00','created_date_max'=>'2023-09-05T07:20:42+00:00'];
    $response = $trackings->getTrackingResults($params);
} catch (TrackingMoreException $e) {
    echo $e->getMessage();
}

print_r($response);

Update a tracking by ID:

require('vendor/autoload.php');

use Trackingmore\TrackingMoreException;
use TrackingMore\Trackings;

$key = 'your api key';
$response = null;
$trackings = new Trackings($key);

try {
    $params = ['customer_name'=>'New name','note'=>'New tests order note'];
    $idString = '9a134772fec0a75ba36ed8162151eb87';
    $response = $trackings->updateTrackingByID($idString,$params);
} catch (TrackingMoreException $e) {
    echo $e->getMessage();
}

print_r($response);