Odoo
Odoo jsonrpc API connections.
API versions of Odoo
The Odoo API is an XML-RPC or JSON-RPC API. There are multiple REST API plugins that can be purchased and installed in on top of the regular Odoo APIs mentioned before. Locoia covers only the JSON-RPC API as it is free of charge and requests can easily be built by viewing the requests made in the Odoo web app's Developer Tools > Network tab and using those payloads for JSON-RPC as described below.
Initial API setup
To start using the Odoo API, one needs to get the these three parameters from the Odoo account database name and a user's id and password.
1. Database
The database name can easily be found, if Odoo is set into debug mode. By adding debug=1
to the web app url, the web app is set it to debug mode, e.g. https://mycompanyname.odoo.com/web?debug=1
Once in debug mode, the database name is visible on the right next to the account name in brackets:
Note: Odoo can be installed locally (e.g. on an AWS cloud instance) or setup via Odoo.sh in the Odoo-cloud. The later avoids and manual installation.
2. User ID
Follow the steps to get it:
Open the developer console of your browser on the Network tab.
In Odoo click on the upper right corner, then click on "Preferences".
Find the request like *your subdomain*.odoo.com/web/dataset/call_kw/res.users/read
Go to the payload tab and open the payload as per the JSON-path:
params.kwargs.context.uid
You found the
uid
e.g. something 2
3. Password:
Password is your user's password of the user you logged in with. Any user can be used to get access.
JSON-RPC Connection
JSON-RPC is an easy way to connect to OdooB. Below one can find a slightly adjusted script based on the one provided from Odoo to make initial testing calls:
To make individual calls, one needs to make further requests, based on the above snippet with the below called.
url = the request url as defined above
object = TBD
execute = stay the same
uid = the user id as defined above
PASSWORD = as defined initially (alternatively the api-key)
"res.partner" = The object to be manipulated
"search" = the request method
args = arguments specifying the request (similar to query string parameters)
Note that Locoia can only send request payloads (body) on POST, PUT or PATCH requests. So for any JSON or XML-RPC requests, POST is to be used.
Searching and Search Operators in Odoo
If you want to search records using custom search operators, a (not too helpful) list of logical and search operators can be found in the source code. The most important take-aways:
When using the Odoo Connector, you might come across simple, specific search actions (such as "Search Partner by Phone), which will make the process as easy as possible for you. However, if you want to execute more elaborate search queries, you can use the custom search endpoints, e.g. "Search Partner by Custom". These Actions allow you to pass your own Tuples (as elaborated above) in as search parameter. Be aware that, as we are using JSON to communicate with your Odoo instance, instead of using simple parenthesis (
, you will have to use square brackets ( [
) in your tuples, like so:
The difference between =
, like
and ilike
=
, like
and ilike
The =
operator will look for a perfect match, the like
operator will add wildcards to the beginning and end of your search term, but is case sensitive, and the ilike
operator is case insensitive.
By adding a =
in front of like and ilike (=like
, =ilike
), you can prevent the search from adding wildcards, but can control the case-sensitivity (e.g. ["name", "ilike", "dog"]
will match dog, bulldog, DOGS, ["name", "=ilike", "dog"]
will only match dog, Dog, DOG, etc.).
Last updated