PHP code example of lekoala / odoo-php-client

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

    

lekoala / odoo-php-client example snippets


use LeKoala\OdooClient\Config;
use LeKoala\OdooClient\Odoo;

$odoo = new Odoo(new Config(
    url: 'https://mycompany.odoo.com',
    db: 'mycompany',
    apiKey: $_ENV['ODOO_API_KEY'],
));

$partners = $odoo->getClient()->searchRead(
    'res.partner',
    [['is_company', '=', true]],
    ['id', 'name', 'email'],
    limit: 20,
    order: 'name asc',
);

$odoo->getClient()->call('sale.order', 'action_confirm', [
    'ids' => [123],
]);

$id = $odoo->getClient()->create('res.partner', ['name' => 'Alice']);

$ids = $odoo->getClient()->createMany('res.partner', [
    ['name' => 'Alice'],
    ['name' => 'Bob'],
]);

use LeKoala\OdooClient\QueryOptions;

$page = $odoo->customers->list([], new QueryOptions(
    limit: 50,
    offset: 100,
    order: 'name asc',
    fields: ['id', 'name', 'email'],
    context: ['lang' => 'fr_BE'],
));

foreach ($odoo->customers->iterate(
    options: new QueryOptions(batchSize: 200, order: 'name asc'),
) as $customer) {
    // The effective order is "name asc, id asc" for stable page boundaries.
}

use GuzzleHttp\Client;
use GuzzleHttp\Psr7\HttpFactory;
use LeKoala\OdooClient\Http\Psr18Transport;
use LeKoala\OdooClient\Config;

$guzzle = new Client([
    'connect_timeout' => 5,
    'timeout' => 30,
]);
$factory = new HttpFactory();

$config = (new Config($url, $db, $apiKey))->setHttpTransport(
    new Psr18Transport($guzzle, $factory, $factory)
);

use LeKoala\OdooClient\Http\Psr18Transport;
use Nyholm\Psr7\Factory\Psr17Factory;
use Symfony\Component\HttpClient\HttpClient as SymfonyHttpClient;
use Symfony\Component\HttpClient\Psr18Client;

$psr18 = new Psr18Client(SymfonyHttpClient::create([
    'timeout' => 30,
]));
$factory = new Psr17Factory();

$config->setHttpTransport(new Psr18Transport($psr18, $factory, $factory));
bash
composer