Odoo provides two API protocols for external integration — XML-RPC and JSON-RPC. This guide covers both with practical Python examples you can use right away.

JSON-RPC Authentication

import requests
import json

url = "http://localhost:8069"
db = "mydb"
username = "admin"
password = "admin"

# Authenticate
session = requests.Session()
resp = session.post(f"{url}/web/session/authenticate", json={
    "jsonrpc": "2.0",
    "params": {
        "db": db,
        "login": username,
        "password": password,
    }
})
print(resp.json()["result"]["uid"])

XML-RPC Authentication

import xmlrpc.client

url = "http://localhost:8069"
db = "mydb"
username = "admin"
password = "admin"

common = xmlrpc.client.ServerProxy(f"{url}/xmlrpc/2/common")
uid = common.authenticate(db, username, password, {})
print("User ID:", uid)

models = xmlrpc.client.ServerProxy(f"{url}/xmlrpc/2/object")

Create Records

partner_id = models.execute_kw(db, uid, password,
    'res.partner', 'create', [{
        'name': 'Acme Corp',
        'email': 'info@acme.com',
        'phone': '+1234567890',
        'is_company': True,
    }])
print("Created partner:", partner_id)

Search and Read

# Search for records
partner_ids = models.execute_kw(db, uid, password,
    'res.partner', 'search', [[
        ['is_company', '=', True]
    ]], {'limit': 10})

# Read specific fields
partners = models.execute_kw(db, uid, password,
    'res.partner', 'read', [partner_ids],
    {'fields': ['name', 'email', 'phone']})

for p in partners:
    print(p['name'], p['email'])

Update Records

models.execute_kw(db, uid, password,
    'res.partner', 'write', [[partner_id], {
        'phone': '+0987654321'
    }])

Delete Records

models.execute_kw(db, uid, password,
    'res.partner', 'unlink', [[partner_id]])

XML-RPC is the standard way to integrate with Odoo from external applications. It works with any programming language that supports XML-RPC — Python, PHP, Java, Node.js, and more.

Share this article

Comments

Join the discussion. Got a question, found an issue, or want to share your experience?

Leave a Comment

Your email stays private. We just use it for replies.

Nothing to preview yet.

Use **bold**, *italic*, `code`, ```code blocks```, [link](url), > quote, - list