Skip to content

Commit c5c1004

Browse files
committed
[IMP] developer/api/external_api: new JSON-2 API
1 parent d4a9931 commit c5c1004

File tree

9 files changed

+380
-210
lines changed

9 files changed

+380
-210
lines changed

content/administration/odoo_online.rst

Lines changed: 12 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -160,49 +160,20 @@ Web Services
160160
============
161161

162162
In order to programmatically retrieve the list of the databases displayed in the
163-
`database manager <https://www.odoo.com/my/databases>`_, call the method `list` of the model
164-
`odoo.database` via a :doc:`Web Service </developer/howtos/web_services>` call.
163+
`database manager <https://www.odoo.com/my/databases>`_, call the method ``list`` of the model
164+
``odoo.database`` via a :doc:`/developer/reference/external_json2_api` call.
165165

166-
Inspired from the examples provided in the :doc:`Web Services </developer/howtos/web_services>`
167-
section, this is how to retrieve this list with the library ``xmlrpc.client``::
166+
Example::
168167

169-
import xmlrpc.client
168+
import requests
170169

171-
172-
APIKEY = 'your_apikey'
170+
APIKEY = "your_apikey"
173171

174-
root = 'https://www.odoo.com/xmlrpc/'
175-
uid = xmlrpc.client.ServerProxy(root + 'common').login('openerp', USER, APIKEY)
176-
sock = xmlrpc.client.ServerProxy(root + 'object')
177-
databases_list = sock.execute('openerp', uid, APIKEY, 'odoo.database', 'list')
178-
179-
And here is the equivalent example with JSON-RPC::
180-
181-
import json
182-
import random
183-
import urllib.request
184-
185-
186-
APIKEY = 'your_apikey'
187-
188-
def json_rpc(url, method, params):
189-
data = {
190-
'jsonrpc': '2.0',
191-
'method': method,
192-
'params': params,
193-
'id': random.randint(0, 1000000000),
172+
requests.post(
173+
"https://www.odoo.com/json/2/odoo.database/list",
174+
headers={
175+
"Authorization": f"bearer {APIKEY}",
176+
"X-Odoo-Database": "openerp",
194177
}
195-
req = urllib.request.Request(url=url, data=json.dumps(data).encode(), headers={
196-
"Content-Type": "application/json",
197-
})
198-
reply = json.loads(urllib.request.urlopen(req).read().decode('UTF-8'))
199-
if reply.get('error'):
200-
raise Exception(reply['error'])
201-
return reply['result']
202-
203-
def call(url, service, method, *args):
204-
return json_rpc(url, 'call', {'service': service, 'method': method, 'args': args})
205-
206-
url = 'https://www.odoo.com/jsonrpc'
207-
uid = call(url, 'common', 'login', 'openerp', USER, APIKEY)
208-
databases_list = call(url, 'object', 'execute', 'openerp', uid, APIKEY, 'odoo.database', 'list')
178+
json={},
179+
)

content/developer/howtos.rst

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ How-to guides
1414
howtos/frontend_owl_components
1515
howtos/website_themes
1616

17-
howtos/web_services
1817
howtos/company
1918
howtos/create_reports
2019
howtos/accounting_localization
@@ -69,11 +68,6 @@ Server-side development
6968

7069
.. cards::
7170

72-
.. card:: Web services
73-
:target: howtos/web_services
74-
75-
Learn more about Odoo's web services.
76-
7771
.. card:: Multi-company guidelines
7872
:target: howtos/company
7973

content/developer/howtos/web_services.rst

Lines changed: 0 additions & 148 deletions
This file was deleted.

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_json2_api
2021
reference/extract_api

content/developer/reference/external_api.rst

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,27 @@
1-
============
2-
External API
3-
============
1+
================
2+
External RPC API
3+
================
4+
5+
.. danger::
6+
7+
.. deprecated:: 19.0
8+
9+
Both the XML-RPC and JSON-RPC APIs are scheduled for removal in Odoo 20.0 (fall 2026). The
10+
:doc:`external_json2_api` acts as replacement.
411

512
Odoo is usually extended internally via modules, but many of its features and
613
all of its data are also available from the outside for external analysis or
714
integration with various tools. Part of the :ref:`reference/orm/model` API is
815
easily available over XML-RPC_ and accessible from a variety of languages.
916

10-
.. important::
11-
Starting with PHP8, the XML-RPC extension may not be available by default.
12-
Check out the `manual <https://www.php.net/manual/en/xmlrpc.installation.php>`_
13-
for the installation steps.
14-
15-
.. note::
16-
Access to data via the external API is only available on *Custom* Odoo pricing plans. Access to
17-
the external API is not available on *One App Free* or *Standard* plans. For more information
18-
visit the `Odoo pricing page <https://www.odoo.com/pricing-plan>`_ or reach out to your Customer
19-
Success Manager.
17+
Starting with PHP8, the XML-RPC extension may not be available by default.
18+
Check out the `manual <https://www.php.net/manual/en/xmlrpc.installation.php>`_
19+
for the installation steps.
2020

21-
.. seealso::
22-
- :doc:`Tutorial on web services <../howtos/web_services>`
21+
Access to data via the external API is only available on *Custom* Odoo pricing plans. Access to
22+
the external API is not available on *One App Free* or *Standard* plans. For more information
23+
visit the `Odoo pricing page <https://www.odoo.com/pricing-plan>`_ or reach out to your Customer
24+
Success Manager.
2325

2426
Connection
2527
==========
24.7 KB
Loading
24.8 KB
Loading
14.3 KB
Loading

0 commit comments

Comments
 (0)