Enable Dark Mode!
By: Risvana AR

How to Handle External APIs in Odoo 16

Technical Odoo 16

The ability of Odoo as an ERP solution to interface with external hardware and software is one of its major benefits. By "communication," we imply the act of transmitting or receiving data, as well as the processes involved in identity or entity verification and data retrieval.

When engaging with external entities that have appropriate APIs, Odoo is highly at ease. These external entities could be biometric instruments, websites, machinery, or anything else that comes to mind. As a result, integrating Odoo with common devices or applications considerably facilitates the growth of the business while also greatly speeding up processes.

Application Programming Interface is referred to as an API. The Odoo ERP system supports APIs. By integrating it with numerous apps developed by third parties, API promotes corporate expansion. If it has the right APIs, Odoo is quite compatible with external entities.

External parties comprise

1) Biometric technology

2) Online programs

3) Industrial machinery

Additionally, use any tools you see fit. Processing is sped up by connecting commonplace devices or applications. Additionally to speeding things up, this considerably facilitates growing our company. The APIs may differ depending on the device or application. However, some commonplace items do use APIs.

APIs may differ from one device or application to another, yet they all have some characteristics.

Let's find out what they are

url = <insert server URL>
db = <insert database name>
username = 'admin'
password = <insert password for your admin user (default: admin)>

URL: Uniform Resource Locator, or URL, is a term used to identify a particular resource on a network. URLs have a special quality. Only when the URL was called directly did it invoke an entity.

Interacting with an online application today, URL is the most often utilized format. The website address for it is http://www.testexample.com. or a variation of this sample link. When it comes to connecting devices, URLs by IP address. The new address was something like

Parameters: The method of transmitting information is known as an argument or a parameter. They could be criteria, credentials, resource identifiers, authentication, or any other sort of phrase or method call. Only the driver that is presently working on the URL can accept the request. Then it executes using the parameters given.

Requests: The URL's little queries are referred to as the request. It is used to deliver and retrieve data as well as requests for authentication.


Simply substituting the key for your password in your programs is how API Keys are used. The login is still active. Since both the API Key and the password ultimately grant access to your user account, you should guard them both carefully (although they can not be used to log in via the interface).


Before they may query the majority of the data, Odoo requires API users to log in.

The xmlrpc/2/common endpoint offers meta-calls, such as the authentication itself or retrieving version data, which are not authentication-required.

The easiest call is to inquire about the server's version in order to confirm that the connection details are accurate before attempting to authenticate.

The authenticate function is used to do the actual authentication and produces a user identification (uid) that may be used in calls that require authentication in place of the login.

common = xmlrpc.client.ServerProxy('{}/xmlrpc/2/common'.format(url))
    "server_version": "16.0",
    "server_version_info": [16, 0, 0, "final", 0],
    "server_serie": "16.0",
    "protocol_version": 1,
uid = common.authenticate(db, username, password, {})

Calling methods:

xmlrpc/2/object is the second endpoint. It is employed to invoke odoo model methods through the execute kw RPC function.

The execute_kw takes different parameters

The database is to be used as a string

The user id is to be used as an integer

The user password is taken as a string

The model name and methods,  a string 

An array/list of parameters is passed by the position

A mapping/dictionary of parameters to be passed by keyword

models = xmlrpc.client.ServerProxy('{}/xmlrpc/2/object'.format(url))
models.execute_kw(db, uid, password, 'res.partner', 'check_access_rights', ['read'], {'raise_exception': False})

It returns a true value, In the case of each record, it can be list records, and we can use as count records, also read records

Using the search() function, the record can be listed and filtered; it accepts a necessary domain filter and returns the database identifiers of all matching records. 

models.execute_kw(db, uid, password, 'res.partner', 'search', [[['is_company', '=', True]]])

In this case, we can use offset and limit that's just a portion of all matching records may be retrieved using the available parameters. And also, search_count is used to find the counts of records.

models.execute_kw(db, uid, password, 'res.partner', 'search', [[['is_company', '=', True]]], {'offset': 10, 'limit': 5})
fileds_get(), it can be used to go over a model's fields and determine which ones appear to be relevant. Odoo offers a search read() shortcut since it is a frequently occurring job. As its name suggests, it is equal to calling search() and read(), but it eliminates making two queries and keeping track of ids. Its arguments are similar to those of search(), but it can also take a list of fields (like read(); it will fetch all fields of matched records if that list is not provided).

Also, we can create a record, update and delete a record; while we previously used fields get() to query a model and have been using an arbitrary model from the beginning, Odoo stores the majority of model metadata inside a small number of meta-models that enable both system queries and on-the-fly model and field changes (with some restrictions) over XML-RPC.

id = models.execute_kw(db, uid, password, 'ir.model', 'create', [{
    'name': "Custom Model",
    'model': "x_custom",
    'state': 'manual',
models.execute_kw(db, uid, password, 'ir.model.fields', 'create', [{
    'model_id': id,
    'name': 'x_name',
    'ttype': 'char',
    'state': 'manual',
    'required': True,
record_id = models.execute_kw(db, uid, password, 'x_custom', 'create', [{'x_name': "test record"}])
models.execute_kw(db, uid, password, 'x_custom', 'read', [[record_id]])
Ir.model.fields: provide details on the fields of Odoo models and enables the addition of additional fields without the need for Python coding.

model id: ir.model to which the field belongs, many2one

name: field description is the field's technical name (used in read or write).

filed_description: a user-friendly label for the field (like a string in fields get)

ttype: the kind of state-creating field

state: whether the field is necessary, read-only, or translate, and whether it was generated using Python code (base) or ir.model.fields (manually).

required, read-only, translate: allows the corresponding field group's flag

groups: filed level for access control

selection, size, on_delete, relation, relation_field, domain: type-specific tweaks and characteristics.

These are common things when we are using the external API in Odoo. We can use these methods in our functions and other related processes.

If you need any assistance in odoo, we are online, please chat with us.


Leave a comment




Cybrosys Technologies Pvt. Ltd.
Neospace, Kinfra Techno Park
Kakkancherry, Calicut
Kerala, India - 673635



Cybrosys Limited
Alpha House,
100 Borough High Street, London,
SE1 1LB, United Kingdom



Cybrosys Technologies Pvt. Ltd.
1st Floor, Thapasya Building,
Infopark, Kakkanad,
Kochi, India - 682030.



Cybrosys Techno Solutions
The Estate, 8th Floor,
Dickenson Road,
Bangalore, India - 560042

Send Us A Message