Skip to content

How to use Odoo External Api in PHP > 8.0

Create records in Odoo ERP with odoo external api using the PHP odoo-xmlrpc library

Shanaya Saxena 1 min read

What is odoo external api?

Just like every other software application, odoo itself also allows to perform certain actions programatically without entering the dashboard.

One of the most common problem developers are facing is removal of xml-rpc module from php versions above 8.0

To get it working, we’ll use the odoo-xmlrpc library

Installation

This library can be easily installed using the composer command below –

composer require alazzi-az/odoo-xmlrpc 
use AlazziAz\OdooXmlrpc\Client;

// Call a method on the Odoo server
$result = $client->call('res.partner', 'search_read', [], ['limit' => 5]);

// Get records from a model
$records = $client->get('res.partner', [], ['name', 'id'], 5);

// Search for records in a model
$searchResult = $client->search('res.partner', []);

// Read records from a model
$records = $client->read('res.partner', $searchResult, ['name', 'id']);

// Create a new record in a model
$id = $client->create('res.partner', [
    'name' => 'John Doe',
    'email' => 'johndoe@example.com'
]);

// Update an existing record in a model
$result = $client->update('res.partner', [$id], [
    'name' => 'Jane Doe',
    'email' => 'janedoe@example.com'
]);

// Delete a record from a model
$result = $client->delete('res.partner', [$id]);

// Get the number of records in a model
$count = $client->count('res.partner', []);

// Get the current user's ID
$uid = $client->getUid();

// Get the version of the Odoo server
$version = $client->getVersion();

Shanaya Saxena

Empowering Developers with Years of Coding Experience

Keep reading