Odoo RPC API
Overview
Odoo exposes a powerful external API via JSON-RPC and XML-RPC, allowing any external application to read, create, update, and delete records. This skill guides you through authenticating, calling models, and building robust integrations.
When to Use This Skill
- Connecting an external app (e.g., Django, Node.js, a mobile app) to Odoo.
- Running automated scripts to import/export data from Odoo.
- Building a middleware layer between Odoo and a third-party platform.
- Debugging API authentication or permission errors.
How It Works
- Activate: Mention
@odoo-rpc-api and describe the integration you need.
- Generate: Get copy-paste ready RPC call code in Python, JavaScript, or curl.
- Debug: Paste an error and get a diagnosis with a corrected call.
Examples
Example 1: Authenticate and Read Records (Python)
import xmlrpc.client
url = 'https://myodoo.example.com'
db = 'my_database'
username = 'admin'
password = 'my_api_key' # Use API keys, not passwords, in production
# Step 1: Authenticate
common = xmlrpc.client.ServerProxy(f'{url}/xmlrpc/2/common')
uid = common.authenticate(db, username, password, {})
print(f"Authenticated as UID: {uid}")
# Step 2: Call models
models = xmlrpc.client.ServerProxy(f'{url}/xmlrpc/2/object')
# Search confirmed sale orders
orders = models.execute_kw(db, uid, password,
'sale.order', 'search_read',
[[['state', '=', 'sale']]],
{'fields': ['name', 'partner_id', 'amount_total'], 'limit': 10}
)
for order in orders:
print(order)
Example 2: Create a Record (Python)
new_partner_id = models.execute_kw(db, uid, password,
'res.partner', 'create',
[{'name': 'Acme Corp', 'email': 'info@acme.com', 'is_company': True}]
)
print(f"Created partner ID: {new_partner_id}")
Example 3: JSON-RPC via curl
curl -X POST https://myodoo.example.com/web/dataset/call_kw \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "call",
"id": 1,
"params": {
"model": "res.partner",
"method": "search_read",
"args": [[["is_company", "=", true]]],
"kwargs": {"fields": ["name", "email"], "limit": 5}
}
}'
# Note: "id" is required by the JSON-RPC 2.0 spec to correlate responses.
# Odoo 16+ also supports the /web/dataset/call_kw endpoint but
# prefer /web/dataset/call_kw for model method calls.
Best Practices
- ✅ Do: Use API Keys (Settings → Technical → API Keys) instead of passwords — available from Odoo 14+.
- ✅ Do: Use
search_read instead of search + read to reduce network round trips.
- ✅ Do: Always handle connection errors and implement retry logic with exponential backoff in production.
- ✅ Do: Store credentials in environment variables or a secrets manager (e.g., AWS Secrets Manager,
.env file).
- ❌ Don't: Hardcode passwords or API keys directly in scripts — rotate them and use env vars.
- ❌ Don't: Call the API in a tight loop without batching — bulk operations reduce server load significantly.
- ❌ Don't: Use the master admin password for API integrations — create a dedicated integration user with minimum required permissions.
Limitations
- Does not cover OAuth2 or session-cookie-based authentication — the examples use API key (token) auth only.
- Rate limiting is not built into the Odoo XMLRPC layer; you must implement throttling client-side.
- The XML-RPC endpoint (
/xmlrpc/2/) does not support file uploads — use the REST-based ir.attachment model via JSON-RPC for binary data.
- Odoo.sh (SaaS) may block some API calls depending on plan; verify your subscription supports external API access.
1---
2name: odoo-rpc-api
3description: Expert on Odoo's external JSON-RPC and XML-RPC APIs. Covers authentication, model calls, record CRUD, and real-world integration examples in Python, JavaScript, and curl.
4category: Development & Code Tools
5source: antigravity
6tags: [python, javascript, node, api, ai, aws]
7url: https://github.com/sickn33/antigravity-awesome-skills/tree/main/skills/odoo-rpc-api
8metadata:
9 source: https://skillmd.com/skills/sickn33/odoo-rpc-api
10---
11
12
13# Odoo RPC API
14
15## Overview
16
17Odoo exposes a powerful external API via JSON-RPC and XML-RPC, allowing any external application to read, create, update, and delete records. This skill guides you through authenticating, calling models, and building robust integrations.
18
19## When to Use This Skill
20
21- Connecting an external app (e.g., Django, Node.js, a mobile app) to Odoo.
22- Running automated scripts to import/export data from Odoo.
23- Building a middleware layer between Odoo and a third-party platform.
24- Debugging API authentication or permission errors.
25
26## How It Works
27
281. **Activate**: Mention `@odoo-rpc-api` and describe the integration you need.
292. **Generate**: Get copy-paste ready RPC call code in Python, JavaScript, or curl.
303. **Debug**: Paste an error and get a diagnosis with a corrected call.
31
32## Examples
33
34### Example 1: Authenticate and Read Records (Python)
35
36```python
37import xmlrpc.client
38
39url = 'https://myodoo.example.com'
40db = 'my_database'
41username = 'admin'
42password = 'my_api_key' # Use API keys, not passwords, in production
43
44# Step 1: Authenticate
45common = xmlrpc.client.ServerProxy(f'{url}/xmlrpc/2/common')
46uid = common.authenticate(db, username, password, {})
47print(f"Authenticated as UID: {uid}")
48
49# Step 2: Call models
50models = xmlrpc.client.ServerProxy(f'{url}/xmlrpc/2/object')
51
52# Search confirmed sale orders
53orders = models.execute_kw(db, uid, password,
54 'sale.order', 'search_read',
55 [[['state', '=', 'sale']]],
56 {'fields': ['name', 'partner_id', 'amount_total'], 'limit': 10}
57)
58for order in orders:
59 print(order)
60```
61
62### Example 2: Create a Record (Python)
63
64```python
65new_partner_id = models.execute_kw(db, uid, password,
66 'res.partner', 'create',
67 [{'name': 'Acme Corp', 'email': 'info@acme.com', 'is_company': True}]
68)
69print(f"Created partner ID: {new_partner_id}")
70```
71
72### Example 3: JSON-RPC via curl
73
74```bash
75curl -X POST https://myodoo.example.com/web/dataset/call_kw \
76 -H "Content-Type: application/json" \
77 -d '{
78 "jsonrpc": "2.0",
79 "method": "call",
80 "id": 1,
81 "params": {
82 "model": "res.partner",
83 "method": "search_read",
84 "args": [[["is_company", "=", true]]],
85 "kwargs": {"fields": ["name", "email"], "limit": 5}
86 }
87 }'
88# Note: "id" is required by the JSON-RPC 2.0 spec to correlate responses.
89# Odoo 16+ also supports the /web/dataset/call_kw endpoint but
90# prefer /web/dataset/call_kw for model method calls.
91```
92
93## Best Practices
94
95- ✅ **Do:** Use **API Keys** (Settings → Technical → API Keys) instead of passwords — available from Odoo 14+.
96- ✅ **Do:** Use `search_read` instead of `search` + `read` to reduce network round trips.
97- ✅ **Do:** Always handle connection errors and implement retry logic with exponential backoff in production.
98- ✅ **Do:** Store credentials in environment variables or a secrets manager (e.g., AWS Secrets Manager, `.env` file).
99- ❌ **Don't:** Hardcode passwords or API keys directly in scripts — rotate them and use env vars.
100- ❌ **Don't:** Call the API in a tight loop without batching — bulk operations reduce server load significantly.
101- ❌ **Don't:** Use the master admin password for API integrations — create a dedicated integration user with minimum required permissions.
102
103## Limitations
104
105- Does not cover **OAuth2 or session-cookie-based authentication** — the examples use API key (token) auth only.
106- **Rate limiting** is not built into the Odoo XMLRPC layer; you must implement throttling client-side.
107- The XML-RPC endpoint (`/xmlrpc/2/`) does not support file uploads — use the REST-based `ir.attachment` model via JSON-RPC for binary data.
108- Odoo.sh (SaaS) may block some API calls depending on plan; verify your subscription supports external API access.