Skip to content

Commit 45a3e66

Browse files
committed
wip api key
1 parent 5230acf commit 45a3e66

File tree

4 files changed

+50
-8
lines changed

4 files changed

+50
-8
lines changed
24.7 KB
Loading
24.8 KB
Loading
14.3 KB
Loading

content/developer/reference/external_json2_api.rst

Lines changed: 50 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22
External JSON-2 API
33
===================
44

5+
.. versionadded:: 19.0
6+
57
Odoo is usually extended internally via modules, but many of its features and all of its data are
68
also available from the outside for external analysis or integration with various tools. Part of
79
the :ref:`reference/orm/model` API is easily available over HTTP via the ``/json/2`` endpoint.
810

911

10-
TL;DR
11-
=====
12+
Examples
13+
========
1214

1315
Request
1416
-------
@@ -42,7 +44,7 @@ POST a json object at the ``/json/2/<model>/<method>`` URL.
4244
User-Agent: mysoftware python-requests/2.25.1
4345
4446
{
45-
"ids": [5],
47+
"ids": [25],
4648
"context": {
4749
"lang": "en_US"
4850
},
@@ -53,7 +55,7 @@ POST a json object at the ``/json/2/<model>/<method>`` URL.
5355
]
5456
}
5557
56-
The JSON must be a json-object containing the arguments for the model's method. The two ``ids``
58+
The body must be a json-object containing the arguments for the model's method. The two ``ids``
5759
and ``context`` are special arguments and serve to craft a recordset on which the method is
5860
executed.
5961

@@ -69,23 +71,22 @@ The exact list of what's available is accessible on the ``/doc`` page of every d
6971
Success response
7072
----------------
7173

72-
The function's return value is serialized as json in the body.
74+
A **200 OK** status with the method's return value serialized as json in the body.
7375

7476
.. code:: http
7577
7678
HTTP/1.1 200 OK
7779
Content-Type: application/json; charset=utf-8
7880
7981
[
80-
{"id": 5, "name": "Deco Addict"}
82+
{"id": 25, "name": "Deco Addict"}
8183
]
8284
8385
8486
Error response
8587
--------------
8688

87-
The errors use a sensible http status code. The error message is serialized as a json string in the
88-
body.
89+
A **4xx**/**5xx** status with the error message serialized as a json string in the body.
8990

9091
.. code:: http
9192
@@ -99,3 +100,44 @@ The complete traceback is available in the server log, at the same date as the e
99100

100101

101102
.. _User-Agent: https://httpwg.org/specs/rfc9110.html#field.user-agent
103+
104+
105+
Authentication & Access Control
106+
===============================
107+
108+
The JSON-2 API uses the access rights of the current user for all operations, and the user is
109+
selected using an API key.
110+
111+
API Key
112+
-------
113+
114+
Create a new API key for a user via :guilabel:`Preferences`, :guilabel:`Account Security`, and
115+
:guilabel:`New API Key`.
116+
117+
.. have the three images appear next to each other
118+
.. list-table::
119+
120+
* - .. image:: external_api/preferences2.png
121+
:align: center
122+
123+
- .. image:: external_api/account-security2.png
124+
:align: center
125+
126+
- .. image:: external_api/new-api-key.png
127+
:align: center
128+
129+
A description and a duration are needed to create a new api key. The description makes it possible
130+
to identify the key, and to determine later whether the key is still in use or should be removed.
131+
It should be as clear and complete as possible. The duration determines the lifetime of the key
132+
after which the the key becomes invalid. It is recommended to set a short duration (typically 1 day)
133+
for interactive usage. It is not possible to create keys that last for more than 3 months, it means
134+
that long lasting keys must be rotated at least once every 3 months.
135+
136+
The :guilabel:`Generate Key` creates a 20 bytes (160 bits) strong random key. Its value appears on
137+
screen, this is the only time and place the key is visible on screen, it must be copied and stored
138+
somewhere safe. If it ever gets compromized or lost, then it must be removed.
139+
140+
The `Secrets Management Cheat Sheet`_ is a document published by the OWASP foundation on how to
141+
safely manage and store secrets such as API keys, with additionnal resources linked at the end.
142+
143+
.. _Secrets Management Cheat Sheet: https://cheatsheetseries.owasp.org/cheatsheets/Secrets_Management_Cheat_Sheet.html#secrets-management-cheat-sheet

0 commit comments

Comments
 (0)