PHP code example of execut / odata-1c

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

    

execut / odata-1c example snippets




use Kily\Tools1C\OData\Client;

/BASE/odata/standard.odata/',[
    'auth' => [
        'YOUR LOGIN', 
        'YOUR PASSWORD'
    ],
    'timeout' => 300,
]);

$product_data = [
    'Артикул'=>'CERTANLY_NONEXISTENT',
    'Description'=>'test test test nonexistent',
];

// Creation
$data = $client->{'Catalog_Номенклатура'}->create($product_data);
echo "CREATED!\n";

// Getting using filter....
$data = $client->{'Catalog_Номенклатура'}->get(null,"Артикул eq 'CERTANLY_NONEXISTENT'");
echo "GOT!\n";
var_dump($data);

// ... or using Ref_Key
$id = $data['value'][0]['Ref_Key'];
$data = $client->{'Catalog_Номенклатура'}->get($id);
echo "GOT BY ID!\n";
var_dump($data);

// Updating
$data = $client->{'Catalog_Номенклатура'}->update($id,[
    'Description'=>'Test description',
]);
echo "UPDATED!\n";

// deletion
$data = $client->{'Catalog_Номенклатура'}->delete($id);
echo "DELETED!\n";

// out metadata
$data = $client->getMetadata();
var_dump($data);

try {
    $data = $client->{'Catalog_Номенклатура'}->get($id);
    if(!$client->isOk()) {
        var_dump('Something went wrong: ',$client->getErrorCode(),$client->getErrorMessage(),$data);
        die();
    }
} catch (Exception $e) {
    log('Error while requested ' . $e->request->url . ': ' . $e->getMessage());
}

use Kily\Tools1C\OData\Profiler;
class CustomProfiler extends Profiler {
    public function begin() {
        echo 'Start request ' . $this->url . ' (' . $this->method . ')';
        if (!empty($this->data)) {
            echo ' with data: ' . var_export($this->data, true) . "\n<br>";
        }
    }

    public function end() {
        echo 'Ending request ' . $this->url . ' (' . $this->method . ')' . "\n<br>"; 
    }
}

$profiler = new Profiler;
$client = new Client($url, $options, $profiler);
$client->setProfiler($profiler);