odoo-lens
v0.1.3
Published
A CLI for reading data from an Odoo instance via the JSON-RPC (/jsonrpc) API. Best use with LLM agents.
Readme
odoo-lens
A small TypeScript client + CLI for reading data from an Odoo instance via the JSON-RPC API (Odoo /jsonrpc).
The higher-level goal is to make it easy for LLMs and coding agents (and humans) to fetch structured Odoo data on demand, so they can answer questions like:
- What is the current status of order
EC-...? - Which picking is blocking shipment?
- What fields exist on a model?
Usage
You can run odoo-lens directly via npx without installing it.
npx odoo-lens list-models --like sale.orderSearch and read records:
npx odoo-lens search-read sale.order '[["name","=","EC-0000000"]]' --fields '["name","state"]' --limit 1Examples you can copy/paste:
# Latest RMAs (returns)
npx odoo-lens search-read rma.order '[]' --fields '["name","state","partner_id","date_rma"]' --limit 5
# Find a customer by email
npx odoo-lens search-read res.partner '[["email","=","[email protected]"]]' --fields '["id","name","email","phone","street","city","state_id","zip"]' --limit 5Runnables scripts (repo checkout): see ./examples.
(You can also install it globally via npm install -g odoo-lens and run odoo-lens version)
Configuration
odoo-lens needs connection details to communicate with your Odoo instance.
By default, it looks for environment variables, a .env file, and a .env.local file (which overrides .env) in your current working directory.
Required keys:
ODOO_URL(orurl)ODOO_DB(ordatabase)ODOO_USERNAME(orusername)ODOO_PASSWORD(orpassword)
Example .env.local:
ODOO_URL=https://my-odoo.example.com
ODOO_DB=my_database
ODOO_USERNAME=admin
ODOO_PASSWORD=supersecretYou can specify a custom env file:
npx odoo-lens --dotenv ./.env.prod versionDirect-IP / self-signed TLS mode
If your Odoo instance is behind a WAF/Cloudflare on the public hostname, you may need to use direct IP access:
ODOO_URL=https://203.0.113.10ODOO_RPC_INSECURE_TLS=trueODOO_RPC_SERVERNAME=odoo.example.com
Notes:
ODOO_RPC_INSECURE_TLS=truedisables TLS certificate verification (required for self-signed certs).ODOO_RPC_SERVERNAMEis used for TLS SNI and will also be sent as the HTTPHostheader.
Optional request headers
If required (WAF allowlist headers, cookies, custom user agent, etc.), you can pass additional HTTP headers for JSON-RPC requests:
ODOO_RPC_HEADERSas JSON, e.g.{ "X-Foo": "bar" }ODOO_RPC_COOKIEfor a rawCookieheader valueODOO_RPC_USER_AGENTfor a custom User-Agent
Legacy environment variables
This project used to use XML-RPC. For backwards compatibility, the following legacy env vars are still supported and map to the JSON-RPC HTTP request settings:
ODOO_XMLRPC_HEADERS->ODOO_RPC_HEADERSODOO_XMLRPC_COOKIE->ODOO_RPC_COOKIEODOO_XMLRPC_USER_AGENT->ODOO_RPC_USER_AGENTODOO_XMLRPC_INSECURE_TLS->ODOO_RPC_INSECURE_TLSODOO_XMLRPC_SERVERNAME->ODOO_RPC_SERVERNAME
How it works (JSON-RPC)
Internally, odoo-lens calls Odoo's JSON-RPC endpoint:
POST /jsonrpcwithcommon.authenticateto get auidPOST /jsonrpcwithobject.execute_kwfor model methods likesearch_read,read_group, etc.
This is the same API the Odoo web client uses, and it tends to work better than XML-RPC in environments that require extra HTTP headers (WAF allowlists, direct-IP host override, etc.).
Example outputs (redacted)
examples/customer-by-email.ts:
{
"email": "[email protected]",
"count": 1,
"partners": [
{
"id": 123,
"name": "Example Customer",
"email": "[email protected]",
"phone": "(***) ***-****",
"street": "...",
"city": "...",
"state_id": [1, "..."],
"zip": "..."
}
]
}examples/latest-rmas.ts:
{
"count": 5,
"rmas": [
{
"id": 1,
"name": "RMA/0001",
"state": "draft",
"partner_id": [1, "..."],
"date_rma": false
}
]
}Local Development
If you want to contribute or modify odoo-lens locally:
- Clone the repository
- Install dependencies:
pnpm install - Create your
.env.local
Run the CLI via the source files:
pnpm dev -- version
pnpm dev -- list-models --like stock.pickingTesting & Building
Run tests and typecheck:
pnpm test
pnpm typecheckBuild the project:
pnpm buildVerify release readiness (runs typecheck, tests, and build):
pnpm release:checkSecurity
- Never commit
.envor.env.local. - Prefer environment variables for CI.
Troubleshooting
JSON-RPC returns HTML instead of JSON
If you see errors like Unexpected token < in JSON at position 0 (or similar), the server likely returned HTML (commonly a WAF / Cloudflare challenge page) instead of JSON.
Try direct-IP mode (above) and/or ensure the /jsonrpc endpoint is allowlisted.
