Odoo is a powerful open-source ERP platform written in Python that can serve as a robust backend for various types of applications—from CRMs to eCommerce systems, inventory management, and more. It comes with a well-structured modular system and provides both XML-RPC and JSON-RPC APIs for backend operations.
In this blog, we’ll walk through:
- Setting up Odoo and modules
- Using Odoo's XML-RPC and JSON-RPC APIs
- Testing APIs with curl commands for major modules (like Contacts, Sales, Inventory, etc.)
Setting Up Odoo and Modules
Step 1: Install Odoo
Install dependencies:
sudo apt update
sudo apt install git python3-pip build-essential wget python3-dev python3-venv libxslt-dev libzip-dev libldap2-dev libsasl2-dev python3-setuptools node-less libpq-dev
Clone Odoo:
git clone https://www.github.com/odoo/odoo --depth 1 --branch 16.0 --single-branch odoo16
cd odoo16
python3 -m venv venv
source venv/bin/activate
pip3 install -r requirements.txt
Start Odoo:
./odoo-bin -d odoo_db -i base --addons-path=addons --db-filter=odoo_db$
Access http://localhost:8069 in your browser.
Step 2: Install Odoo Modules
Go to Apps > Update Apps List > Search and Install:
- Contacts
- Sales
- Inventory
- Project
- Website (Optional)
Or via CLI:
./odoo-bin -d odoo_db -i contacts,sale_management,stock,project --addons-path=addons
Using Odoo's APIs
Odoo provides XML-RPC and JSON-RPC APIs. We’ll focus on JSON-RPC, which is more modern and easier to test with curl.
Authentication API
Before anything, authenticate and get the uid.
Endpoint:
POST http://localhost:8069/jsonrpc
Payload:
{
"jsonrpc": "2.0",
"method": "call",
"params": {
"service": "common",
"method": "authenticate",
"args": ["odoo_db", "admin", "admin", {}]
},
"id": 1
}
Curl:
curl -X POST http://localhost:8069/jsonrpc \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "call",
"params": {
"service": "common",
"method": "authenticate",
"args": ["odoo_db", "admin", "admin", {}]
},
"id": 1
}'
This returns a uid, say 2.
Sample Module APIs & curl Commands
Contacts Module (res.partner)
Create a Contact
curl -X POST http://localhost:8069/jsonrpc \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "call",
"params": {
"service": "object",
"method": "execute_kw",
"args": [
"odoo_db", 2, "admin",
"res.partner", "create",
[{
"name": "Maurice Ombewa",
"email": "maurice@example.com",
"phone": "+254712345678"
}]
]
},
"id": 2
}'
Sales Module (sale.order)
Create a Quotation (Sale Order)
curl -X POST http://localhost:8069/jsonrpc \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "call",
"params": {
"service": "object",
"method": "execute_kw",
"args": [
"odoo_db", 2, "admin",
"sale.order", "create",
[{
"partner_id": 1 // Use a real contact ID
}]
]
},
"id": 3
}'
Inventory Module (stock.picking)
List Incoming Shipments
curl -X POST http://localhost:8069/jsonrpc \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "call",
"params": {
"service": "object",
"method": "execute_kw",
"args": [
"odoo_db", 2, "admin",
"stock.picking", "search_read",
[[["picking_type_code", "=", "incoming"]]],
{"fields": ["name", "state", "scheduled_date"], "limit": 5}
]
},
"id": 4
}'
Project Module (project.task)
Create a Task
curl -X POST http://localhost:8069/jsonrpc \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "call",
"params": {
"service": "object",
"method": "execute_kw",
"args": [
"odoo_db", 2, "admin",
"project.task", "create",
[{
"name": "Blog Tutorial Task",
"project_id": 1 // Use actual project ID
}]
]
},
"id": 5
}'
Other Helpful API Operations
Read records
"method": "read",
"args": [[1, 2], ["name", "email"]]
Search + Read
"method": "search_read",
"args": [[["name", "ilike", "Maurice"]], ["name", "email"]]
Update (Write)
"method": "write",
"args": [[1], {"phone": "+254700000000"}]
Delete (Unlink)
"method": "unlink",
"args": [[1]]
Final Thoughts
Odoo provides a flexible backend that can power complex business applications. With its modular architecture and JSON-RPC APIs, you can integrate it with any frontend—whether it's React, Vue, Flutter, or Android.
In this guide, you've learned how to:
- Set up Odoo and install modules
- Authenticate using JSON-RPC
- Use curl to interact with key models like Contacts, Sales, Inventory, and Projects
Top comments (0)