Skip to content

Commit bd51654

Browse files
committed
[IMP] developer/api/external_api: new JSON-2 API
closes #14535 Signed-off-by: Julien Castiaux (juc) <[email protected]>
1 parent 0819c72 commit bd51654

File tree

9 files changed

+1935
-1561
lines changed

9 files changed

+1935
-1561
lines changed

content/administration/odoo_online.rst

Lines changed: 18 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -160,49 +160,21 @@ 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.
165-
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``::
168-
169-
import xmlrpc.client
170-
171-
172-
APIKEY = 'your_apikey'
173-
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),
194-
}
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')
163+
`database manager <https://www.odoo.com/my/databases>`_, call the method ``list`` of the model
164+
``odoo.database`` via an :doc:`external JSON-2 API </developer/reference/external_api>` call.
165+
166+
.. example::
167+
.. code:: python
168+
169+
import requests
170+
171+
APIKEY = "your_apikey"
172+
173+
requests.post(
174+
"https://www.odoo.com/json/2/odoo.database/list",
175+
headers={
176+
"Authorization": f"bearer {APIKEY}",
177+
"X-Odoo-Database": "openerp",
178+
}
179+
json={},
180+
)

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

0 commit comments

Comments
 (0)