PHP code example of magdv / cargo-php-api-client

1. Go to this page and download the library: Download magdv/cargo-php-api-client 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 / cargo-php-api-client example snippets



use Cargomart\ApiClient\Authentication\LoginPasswordAuthentication;
use Cargomart\ApiClient\Authentication\PsrCacheSessionStorage;
use Cargomart\ApiClient\Authentication\StorageWrapperAuthentication;
use Cargomart\ApiClient\Client;
use Cargomart\ApiClient\Entity\Order\Requests\OrderCreateRequest;
use GuzzleHttp\Client as GuzzleClient;

$guzzle = new GuzzleClient(['base_uri' => 'https://cargomart.ru']);
$client = new Client(
    $guzzle, 
    new StorageWrapperAuthentication(
        new LoginPasswordAuthentication('login', 'password'),
        new PsrCacheSessionStorage($cache)
    )
);

$listReq = $client->apiV2()->order()->get(); // подготовка GET api/v2/order

$rsp = $listReq
    ->qFilterBelong('all')
    ->qFilterStatus([3,4])
    ->do()
; 
// исполнение GET api/v2/order?filter[belong]=all&filter[status][]=3&filter[status][]=4
var_export($rsp->data->order);


$rsp = $listReq
    // Установка заголовка.
    ->xModifyFromEventHeader((int)$rsp->headers['X-Last-Event-Num'] - 10)
    ->do()
;
var_export($rsp->data->order);

$data = new OrderCreateRequest();
$data->isGeneralPartner = true;
$data->kind = 'ftl';
// Пост запрос с телом-объектом.
$rsp = $client->apiV2()->order()->post()->do($data);
var_export($rsp->status);
var_export($rsp->message[0]->title);