The Odoo API in practice

Odoo 19 has a new external API, JSON-2. The old XML-RPC still works, but it is scheduled to disappear. Here is how to use the new one, and the traps we fell into ourselves.

Last checked:

Step by stepFour traps from our own operations
  1. Never hard-code ids
  2. API keys expire
  3. One entry point for many sources
  4. Check the result, not just the response

First: it requires the Custom plan

On odoo.com, the external API belongs to the Custom plan. If you are on Standard, your webshop or accounting program can’t talk to Odoo via the API. If you run Community on your own server, the API is included.

XML-RPC is on its way out

Odoo has marked /xmlrpc, /xmlrpc/2 and /jsonrpc as deprecated. They will be removed in Odoo 22 in autumn 2028, and as early as Odoo Online 21.1 in winter 2027. We noticed when we moved our own installation to Odoo 19 in October 2026. New integrations should be written against JSON-2 from the start.

What a call looks like

A JSON-2 call is a POST to /json/2/<model>/<method> with the API key in the header and the arguments as named fields in JSON.

Find companies by CVR number (curl)

curl -s https://erp.example.dk/json/2/res.partner/search_read \
  -H "Authorization: bearer $ODOO_API_KEY" \
  -H "Content-Type: application/json; charset=utf-8" \
  -H "X-Odoo-Database: prod" \
  -d '{"domain": [["vat", "=", "DK12345678"]], "fields": ["name", "email", "city"], "limit": 5}'

X-Odoo-Database is only needed when there are several databases on the same server and dbfilter doesn’t pick one based on the domain.

Create a contact from a form (Python, requests)

import os
import requests

BASE = "https://erp.example.dk/json/2"
HEADERS = {
    "Authorization": f"bearer {os.environ['ODOO_API_KEY']}",
    "Content-Type": "application/json; charset=utf-8",
    "User-Agent": "webshop-sync/1.0",
}


def call(model: str, method: str, **kwargs):
    r = requests.post(f"{BASE}/{model}/{method}", json=kwargs, headers=HEADERS, timeout=20)
    r.raise_for_status()
    return r.json()


# Look up the country instead of hard-coding an id
dk = call("res.country", "search_read", domain=[["code", "=", "DK"]], fields=["id"], limit=1)[0]["id"]
partner_ids = call("res.partner", "create", vals_list=[{
    "name": "Eksempel ApS",
    "is_company": True,
    "vat": "DK12345678",
    "country_id": dk,
}])
print(partner_ids)

Four traps from our own operations

  1. Never hard-code ids. In our database, subtype_id=1 was the public “Discussions” subtype and not an internal note, so a message meant to be internal came close to being e-mailed to the customer. Look ids up via the XML ID, e.g. env.ref('mail.mt_note'), or with search_read as above.
  2. API keys expire. In Odoo 19 a key can be valid for 90 days at most. Set a reminder, or make the integration report the error clearly when it gets a 401.
  3. One entry point for many sources. Our websites and products send leads to one endpoint in Odoo. Each source has its own token, Odoo stores only a hash of it, and events with the same id are never created twice.
  4. Check the result, not just the response. A “200 OK” doesn’t mean the data landed correctly. The same goes for monitoring: the wrong database can answer 200 with an entirely different page.

When a module beats an integration

If Odoo itself needs to act when data changes, a small module is often simpler than an external integration. Our own modules, for example, read mailboxes in read-only mode directly from Odoo and let an AI model sort enquiries for about $0.0003 per conversation. A module, on the other hand, requires Custom or your own server.

Sources

Last reviewed: 2026-12-04

Questions about the Odoo API

Will our old XML-RPC integration work in Odoo 19?

Yes, for now. It will be removed in Odoo 22 and in Odoo Online 21.1, so plan the switch now.

Where do you create an API key?

Under the user’s preferences, on the Account Security tab. Give the integration its own user with only the access rights it needs.

Can Odoo send webhooks?

Yes, via automation rules that call a URL when a record changes. For larger flows we use n8n – see n8n-hosting.best-choice.dk.

Fixed price, no commitment

Order a free Odoo check

Tell us briefly what you use today and what you want to achieve. A person answers by e-mail with a proposal and a fixed price before any work starts.

  • A fixed price before we start
  • An answer by e-mail, no calls
  • Your details are used only to answer you

Fields marked with * are required.

What is it about?