@@ -160,49 +160,21 @@ Web Services
160160============
161161
162162In 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+ )
0 commit comments