Skip to content

Commit 8e4d066

Browse files
committed
[ADD] odoo_online: add examples to get db list via RPC
Partners and/or fiduciaries need a list of the databases they manage in order to be able to make some RPC requests to all their databases. This commit adds a section in the documentation to explain how to query this new API and provides examples both for XML-RPC and JSON-RPC. closes #12879 Related-to: odoo/internal#3492 Task-id: 3229798 X-original-commit: c6f143d Signed-off-by: Olivier Dony (odo) <[email protected]> Signed-off-by: Paul Morelle (pmo) <[email protected]>
1 parent 8d5f169 commit 8e4d066

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

content/administration/odoo_online.rst

+54
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ database name. It is only displayed if an upgrade is available.
3636
- :ref:`odoo_online/delete`
3737
- :ref:`odoo_online/contact-support`
3838
- :ref:`odoo_online/users`
39+
- :ref:`odoo_online/web-services`
3940

4041
.. _odoo_online/upgrade:
4142

@@ -149,3 +150,56 @@ To remove users, select them and click :guilabel:`Remove`.
149150
.. seealso::
150151
- :doc:`/applications/general/users`
151152
- :doc:`odoo_accounts`
153+
154+
.. _odoo_online/web-services:
155+
156+
Web Services
157+
============
158+
159+
In order to programmatically retrieve the list of the databases displayed in the
160+
`database manager <https://www.odoo.com/my/databases>`_, call the method `list` of the model
161+
`odoo.database` via a :doc:`Web Service </developer/howtos/web_services>` call.
162+
163+
Inspired from the examples provided in the :doc:`Web Services </developer/howtos/web_services>`
164+
section, this is how to retrieve this list with the library ``xmlrpc.client``::
165+
166+
import xmlrpc.client
167+
168+
169+
APIKEY = 'your_apikey'
170+
171+
root = 'https://www.odoo.com/xmlrpc/'
172+
uid = xmlrpc.client.ServerProxy(root + 'common').login('openerp', USER, APIKEY)
173+
sock = xmlrpc.client.ServerProxy(root + 'object')
174+
databases_list = sock.execute('openerp', uid, APIKEY, 'odoo.database', 'list')
175+
176+
And here is the equivalent example with JSON-RPC::
177+
178+
import json
179+
import random
180+
import urllib.request
181+
182+
183+
APIKEY = 'your_apikey'
184+
185+
def json_rpc(url, method, params):
186+
data = {
187+
'jsonrpc': '2.0',
188+
'method': method,
189+
'params': params,
190+
'id': random.randint(0, 1000000000),
191+
}
192+
req = urllib.request.Request(url=url, data=json.dumps(data).encode(), headers={
193+
"Content-Type": "application/json",
194+
})
195+
reply = json.loads(urllib.request.urlopen(req).read().decode('UTF-8'))
196+
if reply.get('error'):
197+
raise Exception(reply['error'])
198+
return reply['result']
199+
200+
def call(url, service, method, *args):
201+
return json_rpc(url, 'call', {'service': service, 'method': method, 'args': args})
202+
203+
url = 'https://www.odoo.com/jsonrpc'
204+
uid = call(url, 'common', 'login', 'openerp', USER, APIKEY)
205+
databases_list = call(url, 'object', 'execute', 'openerp', uid, APIKEY, 'odoo.database', 'list')

0 commit comments

Comments
 (0)