Odoo 16 Development Book

Odoo RPC library (OCA)

It is similar to json-rpc, which is a python module that can connect to Odoo server using RPC

Installation:

pip3 install odoorpc

Connection to Odoo database:

import odoorpc
odoo = odoorpc.ODOO('localhost', port=8016)
print(odoo)
odoo.login(db='DemoDB', login='admin', password='admin')
print(odoo.env.user.name)

This is will give output as follows:

python3 json-test.py
<odoorpc.odoo.ODOO object at 0x7f55ec2a6bb0>
2
Mitchell Admin

Generate API Key:

To connect to the Odoo we use our login credentials, username, and password, for external API such as XML-RPC or JSON_RPC to connect our Odoo database. We can use an API key to authenticate users using external APIs.

odoo Development

We can select a preference to generate an API key.

odoo Development

In the Account security tab, we can see an option to generate API keys.

odoo Development

Click on generate key to create a key and enter the purpose description for the key.

odoo Development

Then we will get a key. Make sure to take a copy and save it because we won’t be able to retrieve it later.

Then click on the preference to view the history.

odoo Development
import xmlrpc.client
url = 'http://0.0.0.0:8016'
database = 'DemoDB'
user = '1'
password = 'f3a905f86f69f9f30fac089769d406dc8d42f965'
common = xmlrpc.client.ServerProxy('{}/xmlrpc/2/common'.format(url))
version_db = common.version()
user = common.authenticate(database, user, password, {})
if user:
  print("User is authenticated....")
else:
  print("Authentication Failed. Please check the credentials")

This gives an output

User is authenticated....

We have used XMLRPC to connect to our database. We have provided the URL, database name, user login and generated API key as a password. When we connect to the database and all the credentials are correct, we receive a message as the user is authenticated….

location

Calicut

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

location

Kochi

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

location

Bangalore

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

Send Us A Message