Odoo is usually extended internally via modules, but many of its features and all of its data are also available from the outside for external analysis or integration with various tools. Part of the Models API is easily available over XML-RPC and accessible from a variety of languages.
If you already have an Odoo server installed, you can just use its parameters
New in version 14.0.
Odoo has support for api keys and (depending on modules or settings) may require these keys to perform webservice operations.
The way to use API Keys in your scripts is to simply replace your password by the key. The login remains in-use. You should store the API Key as carefully as the password as they essentially provide the same access to your user account (although they can not be used to log-in via the interface).
In order to add a key to your account, simply go to your Preferences (or My Profile):
then open the Account Security tab, and click New API Key:
Input a description for the key, this description should be as clear and complete as possible: it is the only way you will have to identify your keys later and know whether you should remove them or keep them around.
Click Generate Key, then copy the key provided. Store this key carefully: it is equivalent to your password, and just like your password the system will not be able to retrieve or show the key again later on. If you lose this key, you will have to create a new one (and probably delete the one you lost).
Once you have keys configured on your account, they will appear above the New API Key button, and you will be able to delete them:
A deleted API key can not be undeleted or re-set. You will have to generate a new key and update all the places where you used the old one.
To make exploration simpler, you can also ask https://demo.odoo.com for a test database:
Odoo requires users of the API to be authenticated before they can query most data.
xmlrpc/2/common endpoint provides meta-calls which don’t require authentication, such as the authentication itself or fetching version information. To verify if the connection information is correct before trying to authenticate, the simplest call is to ask for the server’s version. The authentication itself is done through the
authenticate function and returns a user identifier (
uid) used in authenticated calls instead of the login.
The second endpoint is
xmlrpc/2/object, is used to call methods of odoo models via the
execute_kw RPC function.
Each call to
execute_kw takes the following parameters:
the database to use, a string
the user id (retrieved through
authenticate), an integer
the user’s password, a string
the model name, a string
the method name, a string
an array/list of parameters passed by position
a mapping/dict of parameters to pass by keyword (optional)
For instance to see if we can read the
res.partner model we can call
operation passed by position and
raise_exception passed by keyword (in order to get a true/false result rather than true/error):
Records can be listed and filtered via
By default a search will return the ids of all records matching the condition, which may be a huge number.
limit parameters are available to only retrieve a subset of all matched records.
Rather than retrieve a possibly gigantic list of records and count them,
search_count() can be used to retrieve only the number of records matching the query. It takes the same domain filter as
search() and no other parameter.
Record data is accessible via the
read() method, which takes a list of ids (as returned by
search()) and optionally a list of fields to fetch. By default, it will fetch all the fields the current user can read, which tends to be a huge amount.
Conversedly, picking only three fields deemed interesting.
Listing record fields
fields_get() can be used to inspect a model’s fields and check which ones seem to be of interest.
Because it returns a large amount of meta-information (it is also used by client programs) it should be filtered before printing, the most interesting items for a human user are
string (the field’s label),
help (a help text if available) and
type (to know which values to expect, or to send when updating a record):
Search and read
Because it is a very common task, Odoo provides a
search_read() shortcut which as its name suggests is equivalent to a
search() followed by a
read(), but avoids having to perform two requests and keep ids around.
Records of a model are created using
create(). The method will create a single record and return its database identifier.
create() takes a mapping of fields to values, used to initialize the record. For any field which has a default value and is not set through the mapping argument, the default value will be used.
Multiple records can be updated simultaneously, but they will all get the same values for the fields being set. It is not currently possible to perform “computed” updates (where the value being set depends on an existing value of a record).
Records can be deleted in bulk by providing their ids to
Inspection and introspection
While we previously used
fields_get() to query a model and have been using an arbitrary model from the start, Odoo stores most model metadata inside a few meta-models which allow both querying the system and altering models and fields (with some limitations) on the fly over XML-RPC.
Provides information about Odoo models via its various fields
a human-readable description of the model
the name of each model in the system
whether the model was generated in Python code (
base) or by creating an
ir.model can be used to
query the system for installed models (as a precondition to operations on the model or to explore the system’s content)
get information about a specific model (generally by listing the fields associated with it)
create new models dynamically over RPC
a custom model will initially contain only the “built-in” fields available on all models:
Provides information about the fields of Odoo models and allows adding custom fields without using Python code
the field’s technical name (used in
the field’s user-readable label (e.g.
the type of field to create
whether the field was created via Python code (
base) or via
enables the corresponding flag on the field
type-specific properties and customizations, see the fields documentation for details
Like custom models, only new fields created with
state="manual" are activated as actual fields on the model.