Skip to content

Commit 078ad01

Browse files
committed
[ADD] reference/external_json_api
1 parent 5626e0a commit 078ad01

File tree

2 files changed

+102
-0
lines changed

2 files changed

+102
-0
lines changed

content/developer/reference.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@ Reference
1717
reference/cli
1818
reference/upgrades
1919
reference/external_api
20+
reference/external_json_api
2021
reference/extract_api
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
=================
2+
External JSON API
3+
=================
4+
5+
Odoo is usually extended internally via modules, but many of its features and all of its data are
6+
also available from the outside for external analysis or integration with various tools. Part of
7+
the :ref:`reference/orm/model` API is easily available over HTTP via the ``/json/2`` endpoint.
8+
9+
10+
TL;DR
11+
=====
12+
13+
Request
14+
-------
15+
16+
POST a json object at the ``/json/2/<model>/<method>`` URL.
17+
18+
.. code:: http
19+
20+
POST /json/2/res.partner/search_read HTTP/1.1
21+
Host: mycompany.odoo.com
22+
X-Odoo-Database: mycompany
23+
Authorization: Bearer 6578616d706c65206a736f6e20617069206b6579
24+
Content-Type: application/json; charset=utf-8
25+
User-Agent: mysoftware python-requests/2.25.1
26+
27+
{
28+
"domain": [
29+
["name", "ilike", "%deco%"],
30+
["is_company", "=", true]
31+
],
32+
"fields": ["name"],
33+
}
34+
35+
.. code:: http
36+
37+
POST /json/2/res.partner/write HTTP/1.1
38+
Host: mycompany.odoo.com
39+
X-Odoo-Database: mycompany
40+
Authorization: Bearer 6578616d706c65206a736f6e20617069206b6579
41+
Content-Type: application/json; charset=utf-8
42+
User-Agent: mysoftware python-requests/2.25.1
43+
44+
{
45+
"ids": [5],
46+
"context": {
47+
"lang": "en_US"
48+
},
49+
"vals_list": [
50+
{
51+
"name": "Deco Classic"
52+
}
53+
]
54+
}
55+
56+
The JSON must be a json-object containing the arguments for the model's method. The two ``ids``
57+
and ``context`` are special arguments and serve to craft a recordset on which the method is
58+
executed.
59+
60+
The headers ``Host``, ``Authorization`` (bearer + api key) and ``Content-Type`` are required. The
61+
``X-Odoo-Database`` header is only necessary when multiple databases are hosted behind a same
62+
``Host``. A ``User-Agent`` with the name of the software where the request comes from is
63+
recommended.
64+
65+
The available models and methods depend on the list of modules that are installed in the database.
66+
The exact list of what's available is accessible on the ``/doc`` page of every database.
67+
68+
69+
Success response
70+
----------------
71+
72+
The function's return value is serialized as json in the body.
73+
74+
.. code:: http
75+
76+
HTTP/1.1 200 OK
77+
Content-Type: application/json; charset=utf-8
78+
79+
[
80+
{"id": 5, "name": "Deco Addict"}
81+
]
82+
83+
84+
Error response
85+
--------------
86+
87+
The errors use a sensible http status code. The error message is serialized as a json string in the
88+
body.
89+
90+
.. code:: http
91+
92+
HTTP/1.1 401 Unauthorized
93+
Date: Fri, 18 Jul 2025 08:33:35 GMT
94+
Content-Type: application/json; charset=utf-8
95+
96+
"Invalid apikey"
97+
98+
The complete traceback is available in the server log, at the same date as the error response.
99+
100+
101+
.. _User-Agent: https://httpwg.org/specs/rfc9110.html#field.user-agent

0 commit comments

Comments
 (0)