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.