Simple JavaScript client for connecting to Odoo via XML-RPC calls.
odoo-rpc-client.js
- Core library (the engine)odoo-rpc-examples.js
- Usage examples and demosREADME.md
- This file
- Open your browser's developer tools (F12)
- Go to the Console tab
- Copy and paste the contents of
odoo-rpc-client.js
first - Then copy and paste the contents of
odoo-rpc-examples.js
- Press Enter and watch it run!
Create an HTML file:
<!DOCTYPE html>
<html>
<head>
<title>Odoo RPC Client</title>
</head>
<body>
<h1>Odoo RPC Client</h1>
<p>Check the browser console for output!</p>
<script src="odoo-rpc-client.js"></script>
<script src="odoo-rpc-examples.js"></script>
</body>
</html>
Then open the HTML file in your browser.
Requirements: Node.js 18+ (for built-in fetch support)
# If you have Node.js 18+
node odoo-rpc-examples.js
# Or if you need to combine both files
cat odoo-rpc-client.js odoo-rpc-examples.js > combined.js
node combined.js
For older Node.js versions, install a fetch polyfill:
npm install node-fetch
Then add this line at the top of odoo-rpc-client.js
:
import fetch from 'node-fetch';
deno run --allow-net odoo-rpc-examples.js
Before running, update these settings in odoo-rpc-examples.js
:
const rpc_client = new RPCClient({
baseURL: "YOUR_ODOO_URL_HERE"
});
await rpc_client.login({
db: "YOUR_DATABASE_NAME",
login: "YOUR_USERNAME",
password: "YOUR_PASSWORD"
});
-
Include the library:
// In browser or add <script> tag const client = new RPCClient({ baseURL: "https://your-odoo.com" });
-
Login:
await client.login({ db: "your-db", login: "your-email", password: "your-password" });
-
Make calls:
const partners = await client.call({ model: "res.partner", method: "search_read", args: [[]], // empty domain = get all kwargs: { fields: ["name", "email"], limit: 10 } });
CORS Errors: If running from a browser, your Odoo instance needs to allow CORS from your domain.
Authentication: Make sure your Odoo user has the right permissions for the operations you're trying to perform.
Network: Ensure your Odoo instance is accessible from where you're running the code.
Check odoo-rpc-examples.js
for complete examples including:
- Reading data (search, search_read)
- Creating records (partners, products, invoices)
- Updating records
- Deleting records
- Complex workflows