2
2
External JSON-2 API
3
3
===================
4
4
5
+ .. versionadded :: 19.0
6
+
5
7
Odoo is usually extended internally via modules, but many of its features and all of its data are
6
8
also available from the outside for external analysis or integration with various tools. Part of
7
9
the :ref: `reference/orm/model ` API is easily available over HTTP via the ``/json/2 `` endpoint.
8
10
9
11
10
- TL;DR
11
- =====
12
+ Examples
13
+ ========
12
14
13
15
Request
14
16
-------
@@ -42,7 +44,7 @@ POST a json object at the ``/json/2/<model>/<method>`` URL.
42
44
User-Agent: mysoftware python-requests/2.25.1
43
45
44
46
{
45
- "ids": [5 ],
47
+ "ids": [25 ],
46
48
"context": {
47
49
"lang": "en_US"
48
50
},
@@ -53,7 +55,7 @@ POST a json object at the ``/json/2/<model>/<method>`` URL.
53
55
]
54
56
}
55
57
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 ``
57
59
and ``context `` are special arguments and serve to craft a recordset on which the method is
58
60
executed.
59
61
@@ -69,23 +71,22 @@ The exact list of what's available is accessible on the ``/doc`` page of every d
69
71
Success response
70
72
----------------
71
73
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.
73
75
74
76
.. code :: http
75
77
76
78
HTTP/1.1 200 OK
77
79
Content-Type: application/json; charset=utf-8
78
80
79
81
[
80
- {"id": 5 , "name": "Deco Addict"}
82
+ {"id": 25 , "name": "Deco Addict"}
81
83
]
82
84
83
85
84
86
Error response
85
87
--------------
86
88
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.
89
90
90
91
.. code :: http
91
92
@@ -99,3 +100,44 @@ The complete traceback is available in the server log, at the same date as the e
99
100
100
101
101
102
.. _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