PHP code example of aftership / tracking-sdk
1. Go to this page and download the library: Download aftership/tracking-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 / tracking-sdk example snippets
nt = new \Tracking\Client([
'apiKey' => 'YOUR_API_KEY',
'authenticationType' => \Tracking\Config::AUTHENTICATION_TYPE_API_KEY,
]);
try {
$trackingInfo = $client->tracking->getTrackingById('<tracking-id>');
var_dump($trackingInfo->checkpoints);
} catch (\Tracking\Exception\AfterShipError $e) {
// Handle the error
var_dump($e->getErrorCode());
var_dump($e->getStatusCode());
}
$payload = new \Tracking\API\Tracking\CreateTrackingRequest();
$payload->tracking_number = '<tracking_number>';
$payload->slug = '<slug>';
$trackingInfo = $client->tracking->createTracking($payload);
var_dump($trackingInfo);
$trackingInfo = $client->tracking->deleteTrackingById('<tracking_id>');
var_dump($trackingInfo);
$query = new \Tracking\API\Tracking\GetTrackingsQuery();
$query->setLimit(10)
->setKeyword('123');
$trackingInfo = $client->tracking->getTrackings($query);
var_dump($trackingInfo);
$trackingInfo = $client->tracking->getTrackingById('<tracking_id>');
var_dump($trackingInfo);
$payload = new \Tracking\API\Tracking\UpdateTrackingByIdRequest();
$payload->title = 'test';
$trackingInfo = $client->tracking->updateTrackingById('<tracking_id>', $payload);
var_dump($trackingInfo);
$trackingInfo = $client->tracking->retrackTrackingById('<tracking_id>');
var_dump($trackingInfo);
$payload = new \Tracking\API\Tracking\MarkTrackingCompletedByIdRequest();
$payload->reason = 'DELIVERED';
$trackingInfo = $client->tracking->markTrackingCompletedById('<tracking_id>', $payload);
var_dump($trackingInfo);
$couriers = $client->courier->GetCouriers();
var_dump($couriers);
$payload = new \Tracking\API\Courier\DetectCourierRequest();
$payload->slug = ['<slug>'];
$payload->tracking_number = '<tracking_number>';
$couriers = $client->courier->detectCourier($payload);
var_dump($couriers);
$result = $client->courier->GetCourierConnections();
var_dump($result);
$payload = new \Tracking\API\Courier\DetectCourierRequest();
$payload->slug = ['<slug>'];
$payload->tracking_number = '<tracking_number>';
$result = $client->courier->PostCourierConnections($payload);
var_dump($result);
$payload = new \Tracking\API\EstimatedDeliveryDate\PredictBatchRequest();
$edd = new \Tracking\Model\EstimatedDeliveryDateRequest();
$edd->slug = '<slug>';
$edd->pickup_time = '2024-08-01 06:42:30';
$orginAddress = new \Tracking\Model\OriginAddressEstimatedDeliveryDateRequest();
$orginAddress->country_region = '<ISO 3166-1 country/region code>';
$orginAddress->state = '<ISO 3166-1 country/region code>';
$edd->origin_address = $orginAddress;
$destAddress = new \Tracking\Model\DestinationAddressEstimatedDeliveryDateRequest();
$destAddress->country_region = '<ISO 3166-1 country/region code>';
$destAddress->state = '<ISO 3166-1 country/region code>';
$edd->destination_address = $destAddress;
$payload->estimated_delivery_dates = [$edd];
$result = $client->estimated_delivery_date->predictBatch($payload);
var_dump($result);