Skip to content

Commit 3862578

Browse files
committed
[IMP] developer/api/external_api: new JSON-2 API
1 parent 5838fa7 commit 3862578

File tree

9 files changed

+1895
-1527
lines changed

9 files changed

+1895
-1527
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_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_rpc_api
2021
reference/extract_api

0 commit comments

Comments
 (0)