Enable Dark Mode!
how-to-use-rpc-calls-in-odoo-19.jpg
By: Arjun V P

How to use RPC calls in Odoo 19

Technical Odoo 19 Odoo Enterprises Odoo Community

One of the best practices for communication between the front end of Odoo (JavaScript) and the back end (Python) is done by Remote Procedure Call (RPC). Understanding how to make proper RPC calls in today’s Odoo development is critical, whether you are building dynamic dashboards or widgets.

The web client for Odoo version 19 is completely OWL-based, and the RPC interactions have been made more efficient and modular. All the important details about types of RPC calls and the way they work have been discussed in this blog.

What is RPC in Odoo?

  • RPC (Remote Procedure Call) enables real-time data exchange by executing backend Python methods from the frontend or other systems.
  • For safe and organized communication between the user interface and backend controllers or models, Odoo 19 makes use of the JSON-RPC protocol.

Defining a JSON-RPC Controller in Odoo 19

The HTTP controller system in Odoo allows you to expose endpoints. Here's an illustration:

from odoo import http
class RPCTestController(http.Controller):
   @http.route('/rpc/test/jsonrpc', type='jsonrpc', auth='user', methods=['POST'])
   def rpc_test(self, name):
       return {
           "status": "success",
           "message": f"Hello {name}, RPC is working in Odoo 19 "
       }
  • Use type='jsonrpc' for JSON-RPC routes.
  • Set auth to 'user', 'public', 'none', or 'bearer' as needed.
  • The return value must be JSON serializable

Calling JSON-RPC from JavaScript (Frontend Example)

Odoo's frontend supports making JSON-RPC calls from JavaScript, especially within Owl components:

javascript

/** @odoo-module **/
import { Component, onMounted } from "@odoo/owl";
import { rpc } from "@web/core/network/rpc";
import { registry } from "@web/core/registry";
export class RPCTestComponent extends Component {
   static template = "rpc_test_demo.RPCTestTemplate";
   setup() {
       this.message = "Calling backend...";
       onMounted(async () => {
           const result = await rpc("/rpc/test/jsonrpc", {
               name: "Dev",
           });
           console.log("RPC Result:", result);
           this.message = result.message;
       });
   }
}
registry.category("actions").add(
   "rpc_test_demo.rpc_test_action",
   RPCTestComponent
);
  • The jsonrpc utility in Odoo's web core handles making the request to the backend.
  • The controller receives the data, processes it, and returns a JSON response.

Displaying the Result (OWL Template)

The response is rendered using a simple OWL template:

<t t-name="rpc_test_demo.RPCTestTemplate">
    <div class="o_form_view p-4">
        <h2>JSON-RPC Test (Odoo 19)</h2>
        <p t-esc="message"/>
    </div>
</t>

This confirms that the frontend and backend are fully connected via JSON-RPC.

You should see:

Hello Dev, RPC is working in Odoo 19

The response appears in the browser console

Key Tips for RPC in Odoo 19

  • Since XML-RPC is deprecated in Odoo 19, JSON-RPC should always be used for new customizations. Endpoints must return JSON serializable data and be defined with type='jsonrpc'.
  • Make calls using Odoo's jsonrpc tool in frontend JavaScript (Owl).
  • For frontend and backend partners, record the parameters and anticipated responses for custom APIs.

Advanced: Consuming JSON-RPC from External Apps

With the ability to execute POST requests in accordance with the JSON-RPC specification, your Python script, JavaScript, smartphone, computer, Android, and other third-party services are also able to interact with your Odoo 19 installation. Depending on your specific requirements for your endpoint, these external services will also need to pass along the authentication token in order to authenticate your connection to your Odoo 19 installation. With the JSON-RPC functionality within Odoo 19, you can easily, securely, and efficiently link your third-party services to your Odoo backend solution.

The RPC call, powered by JSON-RPC allows easy building of dynamic, interactive features and integrating external systems in Odoo 19. Furthermore, with its robust backend controller system and clean OWL-based frontend, developers can now design contemporary Odoo applications with less effort.

You can ensure seamless and efficient communication throughout your app using type='jsonrpc' endpoints and the Odoo built-in jsonrpc() frontend utility.

To read more about How to call JSON RPC to Webcontroller in Odoo 19, refer to our blog How to call JSON RPC to Webcontroller in Odoo 19.


Frequently Asked Questions

What is the difference between JSON-RPC and XML-RPC in Odoo 19?

XML-RPC has been deprecated in Odoo 19 and should no longer be used for new developments. JSON-RPC is the recommended approach as it is more secure, lightweight, and integrates seamlessly with Odoo’s OWL-based frontend architecture.

When should I use a JSON-RPC controller instead of calling a model method?

A JSON-RPC controller should be used when you need to create a custom API endpoint, handle requests coming from OWL components or external applications, or require fine-grained control over authentication and routing. For internal frontend-to-backend communication, controllers offer greater flexibility compared to making direct model calls.

Which authentication types are supported in JSON-RPC routes?

Odoo 19 supports several authentication types for JSON-RPC routes. The auth="user" option requires a logged-in user, while auth="public" allows access without login but with limited permissions. The auth="none" option disables authentication and is not suitable for sensitive data. For secure external integrations, auth="bearer" enables token-based authentication.

Can I call JSON-RPC endpoints from external applications?

Yes. External applications such as mobile apps, Python scripts, or third-party services can consume Odoo 19 JSON-RPC endpoints using POST requests. Authentication tokens or session credentials must be included, depending on the endpoint configuration.

What kind of data can be returned from a JSON-RPC endpoint?

The return value of a JSON-RPC route must be JSON-serializable, such as strings, numbers, booleans, lists, or dictionaries. Complex Python objects like recordsets or datetime objects need to be converted into JSON-friendly formats before being returned.

If you need any assistance in odoo, we are online, please chat with us.



0
Comments



Leave a comment



Recent Posts

whatsapp_icon
location

Calicut

Cybrosys Technologies Pvt. Ltd.
Neospace, Kinfra Techno Park
Kakkancherry, Calicut
Kerala, India - 673635

location

Kochi

Cybrosys Technologies Pvt. Ltd.
1st Floor, Thapasya Building,
Infopark, Kakkanad,
Kochi, India - 682030.

location

Bangalore

Cybrosys Techno Solutions
The Estate, 8th Floor,
Dickenson Road,
Bangalore, India - 560042

Send Us A Message