An Ukrposhta PHP SDK based on the official Ukrposhta API.
This library uses PHP 8.1+.
To use the Ukrposhta API, you need to have Bearer and Token for each API sub-portal (eCom, StatusTracking and AddressClassifier). After signing the contract, the bearer and token are issued by your manager. You can find more information here.
- Status Tracking - available.
- Address Classifier (counterparty) - planned.
- Shipments - planned.
To get started, simply require the project using Composer.
composer require tibezh/ukrposhta-php-sdk
Request last status by barcode:
/** @var \Ukrposhta\Tracking\Entities\TrackingStatusInterface $barcodeLastStatus */
$barcodeLastStatus = (new \Ukrposhta\Tracking\Tracking())
->setAccessToken('[BEARER-STATUS-TRACKING-ACCESS-TOKEN]')
// To get results in English.
// ->$this->setRequestLang('EN')
->requestBarcodeLastStatus('[BARCODE]');
// Prints event name value of the last status for the given barcode.
print $barcodeLastStatus->getEventName();
Request all statuses by barcode:
/** @var \Ukrposhta\Tracking\Entities\TrackingStatusCollectionInterface $barcodeLastStatuses */
$barcodeLastStatuses = (new \Ukrposhta\Tracking\Tracking())
->setAccessToken('[BEARER-STATUS-TRACKING-ACCESS-TOKEN]')
// To get results in English.
// ->$this->setRequestLang('EN')
->requestBarcodeStatuses('[BARCODE]');
// Prints "[date]: [eventName]" of each status for the given barcode.
foreach ($data->all() as $item) {
print $item->getDate()->format('c') . ': ' . $item->getEventName();
print '<br>';
}
Request route by barcode:
/** @var \Ukrposhta\Tracking\Entities\TrackingRouteInterface $barcodeRoute */
$barcodeRoute = (new \Ukrposhta\Tracking\Tracking())
->setAccessToken('[BEARER-STATUS-TRACKING-ACCESS-TOKEN]')
// To get results in English.
// ->$this->setRequestLang('EN')
->requestBarcodeRoute('[BARCODE]');
// Prints "[from] -> [to]" information for the given barcode.
print $barcodeRoute->getFrom() ' -> ' . $barcodeRoute->getTo();