PHP code example of awd-studio / nova-poshta

1. Go to this page and download the library: Download awd-studio/nova-poshta 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/ */

    

awd-studio / nova-poshta example snippets




use NovaPoshta\Settings\Settings;

$key      = 'myAuthKeyHash';
$settings = Settings::getInstance()->auth($key);



use NovaPoshta\Settings\Settings;
use NovaPoshta\Models\TrackingDocument;

$key      = 'myAuthKeyHash';
$settings = Settings::getInstance()->auth($key);

$trackNum = '01234567890123'; // Valid track number
$status   = TrackingDocument::track($settings, $trackNum);



use NovaPoshta\Settings\Settings;
use NovaPoshta\Models\Address;

$key      = 'myAuthKeyHash';
$settings = Settings::getInstance()->auth($key);

/**
 * Optional parameters.
 * 
 * @see https://devcenter.novaposhta.ua/docs/services/556d7ccaa0fe4f08e8f7ce43/operations/556d8211a0fe4f08e8f7ce45
 */
$options = [
    'BicycleParking'     => '1',
    'TypeOfWarehouseRef' =>'9a68df70-0267-42a8-bb5c-37f427e36ee4',
    'PostFinance'        => '1',
    'CityName'           =>'Київ',
    'CityRef'            => '20982d74-9b6c-11e2-a57a-d4ae527baec3',
];

// Or set city REF for quick searching:
// $options = [
//     'SettlementRef' => 'e71629ab-4b33-11e4-ab6d-005056801329'
// ];

$address = Address::getBranches($settings, $options);



use NovaPoshta\Settings\Settings;
use NovaPoshta\Models\Address;

$key      = 'myAuthKeyHash';
$settings = Settings::getInstance()->auth($key);

$address  = new Address($settings);

$response = $address->getAreas(); // Areas

$options = [
    'CityRef' => 'ebc0eda9-93ec-11e3-b441-0050568002cf',
];
$response = $address->getStreet($options); // Streets

$response = $address->getSettlements($options); // Settlements



use NovaPoshta\Settings\Settings;
use NovaPoshta\Models\Address;

$key      = 'myAuthKeyHash';
$settings = Settings::getInstance()->auth($key);

$address  = new Address($settings);

// Just start typing, no needed save values to database!

$options = [
    'CityName' => 'К',
    //'CityName' => 'Ки',
    //'CityName' => 'Киї',
];
$response = $address->searchSettlements($options); // Get towns list

$options = [
    'StreetName'    => 'Шев',
    'SettlementRef' => 'e715719e-4b33-11e4-ab6d-005056801329',
    'Limit'         => 10,
];
$response = $address->searchSettlements($options); // Get streets



use NovaPoshta\Settings\Settings;
use NovaPoshta\Models\Common;
use NovaPoshta\Models\Address;

$key      = 'myAuthKeyHash';
$settings = Settings::getInstance()->auth($key);

$recipientCityRef = '8d5a980d-391c-11dd-90d9-001a92567626';

$common   = new Common($settings);
$response = $common->getCargoTypes();
// Or
$response = $common->getPalletsList();
// Or
$response = $common->getMessageCodeText();
// Or
$response = $common->getTimeIntervals($recipientCityRef);

// Get warehouse types
$address  = new Address($settings);
$response = $address->getWarehouseTypes();