@@ -343,15 +343,13 @@ Migrating from XML-RPC / JSON-RPC
343343=================================
344344
345345Both the XML-RPC and JSON-RPC APIs at endpoints ``/xmlrpc ``, ``/xmlrpc/2 `` and ``/jsonrpc `` are
346- scheduled for removal in Odoo 20 (fall 2026).
346+ scheduled for removal in Odoo 20 (fall 2026). Both RPC APIs expose the three same services: common,
347+ db (database) and object. All three services are deprecated.
347348
348- The RPC API defines 3 services:
349-
350- * common
351- * db
352- * object
349+ .. note ::
353350
354- Every service has a replacement in Odoo 19.
351+ The other controllers ``@route(type='jsonrpc') `` (known until Odoo 18 as ``type='json' ``) are not
352+ subject to this deprecation notice.
355353
356354
357355Common service
@@ -380,7 +378,7 @@ The two ``login`` and ``authenticate`` functions return the user id correspondin
380378a successful login. The user id and password are necessary for subsequent RPC calls to the *object *
381379service. The JSON-2 API uses a different authentication scheme where neither the user id nor the
382380password are used. It is still possible to get the user own id doing a JSON-2 request for
383- ``res.users/context_get `` with no ids.
381+ ``res.users/context_get `` with no ids (the current user is extracted from the API key) .
384382
385383Database service
386384----------------
@@ -402,8 +400,7 @@ The db service defines 13 fonctions:
402400#. ``server_version() ``
403401
404402Many of those function are accessible via the ``/web/database `` controllers. Those controllers
405- work hand-in-hand with the HTML form at ``/web/database/manager `` and are accessible via HTTP as
406- well.
403+ work hand-in-hand with the HTML form at ``/web/database/manager `` and are accessible via HTTP.
407404
408405The following controllers use verb ``POST `` and content-type ``application/x-www-form-urlencoded ``.
409406
@@ -436,4 +433,77 @@ Object service
436433The object service defines 2 fonctions:
437434
438435#. ``execute(db, uid, passwd, model, method, *args) ``
439- #. ``execute_kw(db, uid, passwd, model, method, args, kw) ``
436+ #. ``execute_kw(db, uid, passwd, model, method, args, kw={}) ``
437+
438+ They both allow for access to all public model methods, including the generic ORM ones.
439+
440+ Both functions are stateless. It means that the database, user id and user password are to be
441+ provided for each call. The model, method are arguments must likewas be provided. The ``execute ``
442+ function takes as many extra positional arguments as necessary. The ``execute_kw `` function takes a
443+ ``args `` list of positional arguments and an optional ``kw `` dict of keyword arguments.
444+
445+ The records ids are extracted from the first ``args ``. When the called method is decorated with
446+ ``@api.model ``, no record ids are extracted and ``args `` is left as-is. It is only possible to give
447+ a context with ``execute_kw `` as it is extracted from the keyword argument named ``context ``.
448+
449+ Example, to run the following:
450+
451+ .. code :: python
452+
453+ (env[' res.partner' ]
454+ .with_user(2 ) # admin
455+ .with_context(lang = ' en_US' )
456+ .browse([1 , 2 , 3 ])
457+ .read([' name' ], load = None )
458+ )
459+
460+ Using XML-RPC (JSON-RPC would be similar):
461+
462+ .. code :: python
463+
464+ from xmlrpc.client import ServerProxy
465+ object = ServerProxy(... )
466+ ids = [1 , 2 , 3 ]
467+ fields = [' name' ]
468+ load = None
469+
470+ object .execute(" database" , 2 , " admin" , " res.partner" , " read" , ids, fields, load)
471+ object .execute(" database" , 2 , " admin" , " res.partner" , " search" , [
472+ ids,
473+ fields,
474+ ], {
475+ " context" : {" lang" : " en_US" },
476+ " load" : load,
477+ })
478+
479+ The JSON-2 API replaces the object service with a few differences. The database must only be
480+ provided (via the ``X-Odoo-Database `` HTTP header) on systems where there are multiple databases
481+ available for a same domain. The login/password authentication scheme is replaced by an API key (via
482+ the ``Authorization: bearer `` HTTP header). The ``model `` and ``method `` are placed in the URL. The
483+ request body is a JSON object with all the methods arguments, plus ``ids `` and ``context ``. All
484+ the arguments are named, there is no way in JSON-2 to call a function with positional arguments.
485+
486+ Using JSON-2:
487+
488+ .. code :: python
489+
490+ import requests
491+
492+ DATABSE = ...
493+ DOMAIN = ...
494+ API_KEY = " 6578616d706c65206a736f6e20617069206b6579"
495+
496+ requests.post(
497+ f " https:// { DOMAIN } /json/2/res.partner/read " ,
498+ headers = {
499+ # "X-Odoo-Database": DATABASE, # only when DOMAIN isn't enough
500+ " Authorization" : f " bearer { API_KEY } " ,
501+ },
502+ json = {
503+ " ids" : [1 , 2 , 3 ],
504+ " context" : {" lang" : " en_US" },
505+ " fields" : [" name" ],
506+ " load" : None ,
507+ },
508+ ).json()
509+
0 commit comments