Enable Dark Mode!
how-mobo-apps-communicate-with-odoo-xml-rpc-vs-json-rpc.jpg
By: Shalbin MP

How Mobo Apps Communicate with Odoo (XML-RPC vs JSON-RPC)

Technical Flutter mobo

Odoo is a comprehensive open-source ERP system that provides various APIs for external integration. When building Flutter applications that need to communicate with Odoo, developers have two primary protocols to choose from: XML-RPC and JSON-RPC. Both protocols enable remote procedure calls (RPC), allowing your Flutter app to execute methods on the Odoo server and retrieve data.

This guide explores both approaches, provides practical code examples, and helps you understand when to use each protocol for your Flutter-Odoo integration.

What is Remote Procedure Call (RPC)?

A Remote Procedure Call (RPC) is when a computer program causes a procedure to execute on a different server, typically over a network. The programmer writes code as if calling a local function, without explicitly coding the details for the remote interaction. This creates a seamless client-server interaction where the Flutter app (client) makes requests to the Odoo server (server) to execute business logic and retrieve data.

Understanding XML-RPC

XML-RPC is a remote procedure call protocol that uses XML to encode its calls and HTTP as a transport mechanism. In XML-RPC, a client performs an RPC by sending an HTTP request to a server and receives an HTTP response. A call can have multiple parameters and return one result.

Key Characteristics of XML-RPC

  • Uses XML format for encoding data
  • Transport mechanism: HTTP/HTTPS
  • Well-documented with extensive examples
  • Easy to understand syntax
  • Mature protocol with broad language support

Odoo XML-RPC Endpoints

Odoo provides two main XML-RPC endpoints:

  • /xmlrpc/2/common - For authentication and meta-operations
  • /xmlrpc/2/object - For calling Odoo model methods via execute_kw

Flutter XML-RPC Implementation

To use XML-RPC in Flutter, you'll need to add the xml_rpc package to your pubspec.yaml:

pubspec.yaml

dependencies:
  xml_rpc: ^5.0.0

XML-RPC Client Class Example:

odoo_xmlrpc_client.dart

import 'package:xml_rpc/client.dart' as xml_rpc;
 
class OdooXmlRpcClient {
  String url;
  String db;
  String username;
  String password;
  int? uid;
  
  late String commonURL;
  late String objectURL;
  
  OdooXmlRpcClient({
    required this.url,
    required this.db,
    required this.username,
    required this.password,
  }) {
    commonURL = url + '/xmlrpc/2/common';
    objectURL = url + '/xmlrpc/2/object';
  }
  
  // Authentication
  Future<dynamic> authenticate() async {
    uid = await xml_rpc.call(
      commonURL,
      'authenticate',
      [db, username, password, {}]
    );
    return uid;
  }
  
  // Search records
  Future<List<dynamic>> search(
    String model,
    List<dynamic> domain
  ) async {
    return await xml_rpc.call(
      objectURL,
      'execute_kw',
      [db, uid, password, model, 'search', domain]
    );
  }
  
  // Search and read records
  Future<List<dynamic>> searchRead(
    String model,
    List<dynamic> domain,
    Map<String, Object> params
  ) async {
    return await xml_rpc.call(
      objectURL,
      'execute_kw',
      [db, uid, password, model, 'search_read', domain, params]
    );
  }
  
  // Create a record
  Future<dynamic> create(
    String model,
    List<dynamic> values
  ) async {
    return await xml_rpc.call(
      objectURL,
      'execute_kw',
      [db, uid, password, model, 'create', values]
    );
  }
  
  // Update a record
  Future<dynamic> write(
    String model,
    List<dynamic> ids,
    Map<String, dynamic> values
  ) async {
    return await xml_rpc.call(
      objectURL,
      'execute_kw',
      [db, uid, password, model, 'write', [ids, values]]
    );
  }
  
  // Delete a record
  Future<dynamic> unlink(
    String model,
    List<dynamic> ids
  ) async {
    return await xml_rpc.call(
      objectURL,
      'execute_kw',
      [db, uid, password, model, 'unlink', [ids]]
    );
  }
}

Usage Example:

main.dart

// Initialize the client
final client = OdooXmlRpcClient(
  url: 'https://your-odoo-instance.com',
  db: 'your_database',
  username: 'admin',
  password: 'admin',
);
 
// Authenticate
await client.authenticate();
 
// Fetch partners
final partners = await client.searchRead(
  'res.partner',
  [],
  {
    'fields': ['id', 'name', 'email'],
    'limit': 10,
  }
);
 
print('Partners: $partners');

Understanding JSON-RPC

JSON-RPC is a remote procedure call protocol encoded in JSON. It is similar to XML-RPC but uses the more lightweight JSON format. JSON-RPC allows for notifications (data sent to the server that does not require a response) and supports multiple calls that may be answered asynchronously.

Key Characteristics of JSON-RPC

  • Uses JSON format for encoding data (more lightweight than XML)
  • Transport mechanism: HTTP/HTTPS
  • Supports asynchronous calls
  • Allows notifications without responses
  • Modern and efficient data format

Odoo JSON-RPC Endpoint

Odoo exposes a single JSON-RPC endpoint:

  • /jsonrpc - Handles all operations including authentication and model methods

Flutter JSON-RPC Implementation

The recommended approach for JSON-RPC in Flutter is using the odoo_rpc package:

pubspec.yaml

dependencies:
  odoo_rpc: ^0.5.2

JSON-RPC Client Example (using odoo_rpc package):

odoo_jsonrpc_client.dart

import 'package:odoo_rpc/odoo_rpc.dart';
 
class OdooJsonRpcClient {
  late OdooClient client;
  
  OdooJsonRpcClient(String baseUrl) {
    client = OdooClient(baseUrl);
  }
  
  // Authenticate
  Future<OdooSession> authenticate(
    String database,
    String username,
    String password
  ) async {
    return await client.authenticate(
      database,
      username,
      password
    );
  }
  
  // Call Odoo model methods
  Future<dynamic> callKw(Map<String, dynamic> params) async {
    return await client.callKw(params);
  }
  
  // Search and read records
  Future<List<dynamic>> searchRead({
    required String model,
    List<dynamic>? domain,
    List<String>? fields,
    int? limit,
  }) async {
    return await client.callKw({
      'model': model,
      'method': 'search_read',
      'args': [],
      'kwargs': {
        'domain': domain ?? [],
        'fields': fields ?? [],
        'limit': limit ?? 80,
      },
    });
  }
  
  // Create a record
  Future<int> create(
    String model,
    Map<String, dynamic> values
  ) async {
    return await client.callKw({
      'model': model,
      'method': 'create',
      'args': [values],
      'kwargs': {},
    });
  }
  
  // Update a record
  Future<bool> write(
    String model,
    int id,
    Map<String, dynamic> values
  ) async {
    return await client.callKw({
      'model': model,
      'method': 'write',
      'args': [[id], values],
      'kwargs': {},
    });
  }
  
  // Delete a record
  Future<bool> unlink(String model, int id) async {
    return await client.callKw({
      'model': model,
      'method': 'unlink',
      'args': [[id]],
      'kwargs': {},
    });
  }
  
  // Logout
  Future<void> logout() async {
    await client.destroySession();
  }
}

Usage Example:

main.dart

// Initialize the client
final client = OdooXmlRpcClient(
  url: 'https://your-odoo-instance.com',
  db: 'your_database',
  username: 'admin',
  password: 'admin',
);
 
// Authenticate
await client.authenticate();
 
// Fetch partners
final partners = await client.searchRead(
  'res.partner',
  [],
  {
    'fields': ['id', 'name', 'email'],
    'limit': 10,
  }
);
 
print('Partners: $partners');

XML-RPC vs JSON-RPC: Detailed Comparison

Both protocols are capable of handling Odoo integration, but they have distinct characteristics that may make one more suitable for your specific use case.

FeatureXML-RPCJSON-RPC
Data FormatXML (verbose, larger payload)JSON (lightweight, smaller payload)
PerformanceSlower due to XML parsing overheadFaster, efficient JSON parsing
Bandwidth UsageHigher (verbose XML tags)Lower (compact JSON format)
DocumentationExtensive with many examplesLess documentation, growing community
Learning CurveEasier, simple syntaxModerate, requires understanding of structure
Flutter Packagexml_rpcodoo_rpc (recommended)
Endpoints

/xmlrpc/2/common

/xmlrpc/2/object

/jsonrpc
Async SupportSynchronous onlySupports asynchronous calls
Session ManagementManual (pass uid and password each call)Automatic session tracking via cookies
Best ForSimple integrations, learning purposesProduction apps, complex integrations

When to Use Each Protocol

Use XML-RPC When:

  • You're learning Odoo integration and want extensive documentation
  • Building simple proof-of-concept applications
  • Working with legacy systems that only support XML-RPC
  • You need maximum compatibility across different platforms

Use JSON-RPC When:

  • Building production-grade Flutter applications
  • Performance and bandwidth optimization are important
  • You need modern features like session management and async support
  • Working with mobile apps where data usage matters
  • You want a cleaner, more maintainable codebase

Best Practices for Odoo-Flutter Integration

  1. Error Handling: Always implement comprehensive error handling for network issues, authentication failures, and server errors.
  2. Security: Never hardcode credentials. Use secure storage solutions like flutter_secure_storage for sensitive data.
  3. Session Management: Store and reuse sessions to avoid repeated authentication calls.
  4. Performance: Use pagination and field filtering to minimize data transfer.
  5. Testing: Test thoroughly with both Odoo Community and Enterprise editions.
  6. CORS Configuration: For web apps, ensure proper CORS headers are configured on your Odoo server.

Both XML-RPC and JSON-RPC are viable options for integrating Flutter applications with Odoo. XML-RPC offers simplicity and extensive documentation, making it ideal for learning and simple integrations. However, JSON-RPC is the recommended choice for production applications due to its superior performance, modern features, and efficient data handling.

For most Flutter developers building serious business applications, the odoo_rpc package provides an excellent JSON-RPC implementation with features like automatic session management, stream-based updates, and comprehensive error handling. This makes it the preferred solution for enterprise-grade mobile applications.

Regardless of which protocol you choose, proper error handling, security practices, and performance optimization should always be top priorities when integrating with Odoo's powerful ERP system.

For most Flutter developers building serious business applications, Mobo provides a reliable integration solution with secure session management, real-time updates, and strong error handling—making it ideal for scalable, enterprise-grade mobile apps.

To read more about How to Fetch Related Fields (Many2one & One2many) from Odoo in a Flutter App, refer to our blog How to Fetch Related Fields (Many2one & One2many) from Odoo in a Flutter App.


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



0
Comments



Leave a comment



whatsapp_icon
location

Calicut

Cybrosys Technologies Pvt. Ltd.
Neospace, KINFRA Techno Park
Kakkanchery, 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