3👍
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.
Read more : https://www.odoo.com/documentation/14.0/webservices/odoo.html
Example of XML-RPC by using Django rest framework:
import xmlrpclib
from rest_framework.decorators import api_view
from rest_framework.response import Response
db = '<DB-NAME>'
url = '<your-host-name:8069>'
models = xmlrpclib.ServerProxy('{}/xmlrpc/2/object'.format(url))
common = xmlrpclib.ServerProxy('{}/xmlrpc/2/common'.format(url))
def get_uid():
username = '<your-odoo-username>'
password = '<your-odoo-password>'
uid = common.authenticate(db, username, password, {})
return uid, password
# create default execute method (Odoo Xmlrpc)
def execute(*args):
uid = get_uid()[0]
password = get_uid()[1]
return models.execute_kw(db, uid, password, *args)
# Rest Api for get contact list of odoo with name only
@api_view(['GET'])
def get_contacts_list(request):
contacts = execute('res.partner', 'search_read', [[]], {'fields':['name']})
return Response({'result': contacts, 'status_code': 200})
Source:stackexchange.com