PHP code example of ktscript / moysklad

1. Go to this page and download the library: Download ktscript/moysklad 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/ */

    

ktscript / moysklad example snippets


use MoySklad\ApiClient;

$api = new ApiClient('host', true, [
    'login' => 'your_login',
    'password' => 'your_password',
]);

$counterpartyList = $api->entity()->counterparty()->getList();
$counterparty = $api->entity()->counterparty()->get('id');

use MoySklad\Util\Param\Limit;
use MoySklad\Util\Param\Offset;
use MoySklad\Util\Param\Order;
use MoySklad\Util\Param\Search;
use MoySklad\Util\Param\EntityFilter;
use MoySklad\Util\Param\StandardFilter;

$params = [
    Limit::eq(50),
    Offset::eq(10),
    Order::asc('name'),
    Order::desc('date'),
    Search::eq('some interesting thing'),
    EntityFilter::eq('product', $product),
    EntityFilter::neq('pricetype', $pricetype),
    StandardFilter::eq('region_id', $regionId),
    StandardFilter::gte('created', $createdDate),
    StandardFilter::like('name', 'ame'),
];

$counterpartyList = $api->entity()->counterparty()->getList($params);

$product = new Product();
$product->name = 'Новый продукт';

$product = $api->entity()->product()->create($product);

$product->name = 'new name';
$product = $api->entity()->product()->update($product);

$counterpartyAccountsList = $api->entity()->counterparty()->getAccountsList('counterparty_id');

$counterpartyAccount = $api->entity()->counterparty()->getAccount('counterparty_id', 'account_id');


$counterparty = $api->entity()->counterparty()->get('id');
$addressCity = $counterparty->legalAddressFull->city; // null

$counterparty->legalAddressFull->fetch();
$addressCity = $counterparty->legalAddressFull->city; // название города


$api->entity()->purchaseorder()->getList([StandardFilter::eq('name', 'my_name')]);

$api->entity()->purchaseorder()->first(); //берет первый из возвращаемого списка 
$api->entity()->purchaseorder()->first('name', 'my_name'); //берет первый из фильтрованного возвращаемого списка 

$productSupply = new ProductSupply();
$productSupply->fill([
    'name' => 'my_name',
    'organization' => $organization,
    'store' => $store,
    'agent' => $counterparty,
    'positions' => $positionsList,
]);

$supply = $api->entity()->supply()->create($productSupply);

$demand = $api->entity()->demand()->create($customerOrder);