PHP code example of magdv / mt-forwarder-registry-api

1. Go to this page and download the library: Download magdv/mt-forwarder-registry-api 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/ */

    

magdv / mt-forwarder-registry-api example snippets


use MagDV\MtForwarderRegistry\Configuration;
use MagDV\MtForwarderRegistry\Api\RegistryApi;
use MagDV\MtForwarderRegistry\Api\SystemApi;
use MagDV\MtForwarderRegistry\ApiException;
use MagDV\MtForwarderRegistry\Model\Health;

$config = Configuration::getDefaultConfiguration()
    ->setHost('https://forwarder-registry.log.magdv.com');
    // defaults: timeout=1.0s, connect_timeout=0.5s
    // ->setTimeout(2.0)->setConnectTimeout(1.0);

$system = new SystemApi(null, $config);
$health = $system->getHealth(); // liveness: обычно 200

// getReady(): при неготовности сервис отвечает 503 —
// клиент бросает ApiException; тело Health в getResponseObject().
try {
    $ready = $system->getReady();
} catch (ApiException $e) {
    if ($e->getCode() === 503) {
        /** @var Health|null $body */
        $body = $e->getResponseObject();
        // $body?->getReady() === false
    }
    throw $e;
}

$api = new RegistryApi(null, $config);
$meta = $api->getMeta();
$list = $api->listForwarders(inn: '7707083893', deleted: 'false', limit: 50);
$byInn = $api->getForwardersByINN('7707083893');
$one = $api->getForwarderByRegistryNumber('GL-B044-00112-00/00000051');

$config = Configuration::getDefaultConfiguration()
    ->setHost('https://forwarder-registry.log.magdv.com')
    ->setTimeout(3.0)
    ->setConnectTimeout(1.0);