@@ -160,49 +160,20 @@ 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.
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+ )
0 commit comments