PHP code example of aftership / aftership-php-sdk

1. Go to this page and download the library: Download aftership/aftership-php-sdk library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

aftership / aftership-php-sdk example snippets




$key = 'AFTERSHIP API KEY';

$couriers = new AfterShip\Couriers($key);
$trackings = new AfterShip\Trackings($key);
$last_check_point = new AfterShip\LastCheckPoint($key);



$key = 'AFTERSHIP API KEY';

$couriers = new AfterShip\Couriers($key);
$trackings = new AfterShip\Trackings($key);
$notifications = new AfterShip\Notifications($key);
$last_check_point = new AfterShip\LastCheckPoint($key);



$api_key = 'AFTERSHIP API KEY';
$api_secret = 'Your api secret'; // if the encryption_method = RSA, the api_secret is PEM private key
$encryption_method = 'AES or RSA';
$encryption_password = 'PEM pass phrase'; 

$key = ['api_key' => $api_key, 'api_secret' => $api_secret, 'encryption_method' => $encryption_method, 'encryption_password' => $encryption_password]

$couriers = new AfterShip\Couriers($key);
$trackings = new AfterShip\Trackings($key);
$last_check_point = new AfterShip\LastCheckPoint($key);



$api_key = 'AFTERSHIP API KEY';

$curl_opt = [CURLOPT_PROXY => 'http://example.com', 'CURLOPT_PROXYPORT' => '8080']

$couriers = new AfterShip\Couriers($key, null, $curl_opt);
$trackings = new AfterShip\Trackings($key, null, $curl_opt);
$last_check_point = new AfterShip\LastCheckPoint($key, null, $curl_opt);

try {
  $couriers = new AfterShip\Couriers('AFTERSHIP_API_KEY');
  $response = $couriers->get();
}catch(\AfterShipException $e) {
    echo $e->getMessage();
}


$couriers = new AfterShip\Couriers('AFTERSHIP_API_KEY');
$response = $couriers->get();

$couriers = new AfterShip\Couriers('AFTERSHIP_API_KEY');
$response = $couriers->all();

$courier = new AfterShip\Couriers('AFTERSHIP_API_KEY');
$response = $courier->detect('1234567890Z');

$trackings = new AfterShip\Trackings('AFTERSHIP_API_KEY');
$tracking_info = [
    'slug'    => 'dhl',
    'title'   => 'My Title',
];
$response = $trackings->create('RA123456789US', $tracking_info);

$trackings = new AfterShip\Trackings('AFTERSHIP_API_KEY');
$response = $trackings->delete('dhl', 'RA123456789US');

$trackings = new AfterShip\Trackings('AFTERSHIP_API_KEY');
$response = $trackings->delete('abcustom', 'RA123456789US', ['tracking_postal_code' => '90199']);

$trackings = new AfterShip\Trackings('AFTERSHIP_API_KEY');
$response = $trackings->deleteById('53df4a90868a6df243b6efd8');

$trackings = new AfterShip\Trackings('AFTERSHIP_API_KEY');
$options = [
    'page'  => 1,
    'limit' => 10
];
$response = $trackings->all($options);

$trackings = new AfterShip\Trackings('AFTERSHIP_API_KEY');
$response = $trackings->get('dhl', 'RA123456789US', array('title','order_id'));

$trackings = new AfterShip\Trackings('AFTERSHIP_API_KEY');
$response = $trackings->get('dhl', 'RA123456789US', array('fields' => 'title,order_id'));

$trackings = new AfterShip\Trackings('AFTERSHIP_API_KEY');
$response = $trackings->get('dhl', 'RA123456789US', array('lang' => 'en'));

$trackings = new AfterShip\Trackings('AFTERSHIP_API_KEY');
$response = $trackings->getById('53df4a90868a6df243b6efd8', array('title','order_id'));

$trackings = new AfterShip\Trackings('AFTERSHIP_API_KEY');
$params = array(
    'smses'             => [],
    'emails'            => [],
    'title'             => '',
    'customer_name'     => '',
    'order_id'          => '',
    'order_id_path'     => '',
    'custom_fields'     => []
);
$response = $trackings->update('dhl', 'RA123456789US', $params);

$trackings = new AfterShip\Trackings('AFTERSHIP_API_KEY');
$params = array(
    'smses'             => [],
    'emails'            => [],
    'title'             => '',
    'customer_name'     => '',
    'order_id'          => '',
    'order_id_path'     => '',
    'custom_fields'     => []
);
$response = $trackings->updateById('53df4a90868a6df243b6efd8', $params);

$trackings = new AfterShip\Trackings('AFTERSHIP_API_KEY');
$response = $trackings->retrack('dhl','RA123456789US');

$trackings = new AfterShip\Trackings('AFTERSHIP_API_KEY');
$response = $trackings->retrack('abcustom','RA123456789US', ['tracking_postal_code' => '90199']);

$trackings = new AfterShip\Trackings('AFTERSHIP_API_KEY');
$response = $trackings->retrackById('53df4a90868a6df243b6efd8');

$last_check_point = new AfterShip\LastCheckPoint('AFTERSHIP_API_KEY');
$response = $last_check_point->get('dhl','RA123456789US');

$last_check_point = new AfterShip\LastCheckPoint('AFTERSHIP_API_KEY');
$response = $last_check_point->getById('53df4a90868a6df243b6efd8');

$notifications = new AfterShip\Notifications('AFTERSHIP_API_KEY');
$response = $notifications->create('ups', '1ZV90R483A33906706', [
                'emails' => ['[email protected]']
            ])

$notifications = new AfterShip\Notifications('AFTERSHIP_API_KEY');
$response = $notifications->create('abcustom', '1ZV90R483A33906706', [
                'emails' => ['[email protected]']
            ], ['tracking_postal_code' => '90199'])

$notifications = new AfterShip\Notifications('AFTERSHIP_API_KEY');
$response = $notifications->createById('53df4a90868a6df243b6efd8');

$notifications = new AfterShip\Notifications('AFTERSHIP_API_KEY');
$response = $notifications->delete('ups', '1ZV90R483A33906706', [
                  'emails' => ['[email protected]']
              ]);

$notifications = new AfterShip\Notifications('AFTERSHIP_API_KEY');
$response = $notifications->delete('abcustom', '1ZV90R483A33906706', [
                  'emails' => ['[email protected]']
              ], ['tracking_postal_code' => '90199']);

$notifications = new AfterShip\Notifications('AFTERSHIP_API_KEY');
$response = $notifications->deleteById('53df4d66868a6df243b6f882'));

$notifications = new AfterShip\Notifications('AFTERSHIP_API_KEY');
$response = $notifications->get('dhl', '2254095771'));

$notifications = new AfterShip\Notifications('AFTERSHIP_API_KEY');
$response = $notifications->getById('53df4a90868a6df243b6efd8', ['fields' => 'customer_name']);

composer