Share on:

Table of Contents

Odoo REST API: How to Build and Connect It to Any App

An Odoo REST API lets your website, mobile app or third-party software read and write Odoo data without anyone logging in to the Odoo interface. Odoo does not ship a classic REST API in older versions, but you can get the same result in two ways: use the built-in external API, or build your own endpoints with custom controllers. This guide explains both, with working code, so you can choose the right approach and connect Odoo to almost any app.

Choose Your Odoo REST API Approach

Before writing code, pick the method that fits your project.

Approach Best for Effort
Built-in external API (XML-RPC / JSON-RPC, JSON-2 in newer versions) Scripts, quick integrations, data sync Low
Custom controllers (your own REST-style endpoints) Mobile apps, websites, clean URLs, custom responses Medium

Use the built-in API when you only need to read or write standard records. Build custom endpoints when you want clean URLs such as /api/v1/products, custom JSON responses, or tight control over what each client can access.

Use Odoo’s Built-in External API

Odoo exposes its models through external APIs on every installation. You authenticate with a database name, a user and an API key (create one in your user’s Preferences, under Account Security).

Example: read records with Python (XML-RPC)

python
import xmlrpc.client

url = 'https://yourcompany.odoo.com'
db = 'your_database'
username = 'api_user@example.com'
api_key = 'YOUR_API_KEY'

common = xmlrpc.client.ServerProxy(f'{url}/xmlrpc/2/common')
uid = common.authenticate(db, username, api_key, {})

models = xmlrpc.client.ServerProxy(f'{url}/xmlrpc/2/object')
products = models.execute_kw(
    db, uid, api_key,
    'product.product', 'search_read',
    [[['sale_ok', '=', True]]],
    {'fields': ['name', 'list_price'], 'limit': 10}
)
print(products)

This works for any model and any method your user is allowed to call. Newer Odoo versions are adding a JSON-based external API, so check the official documentation for your version before building on XML-RPC for the long term.

The downside is that the URLs are generic and the responses are Odoo-shaped. For a mobile app or a customer-facing integration, custom endpoints are usually cleaner.

Build a Custom Odoo REST API with Controllers

Controllers let you define your own URLs, accept JSON, and return exactly the data your app needs.

Step 1: Create a controller file

Inside your custom module, add controllers/main.py and import it in controllers/__init__.py. Also import controllers in the module’s __init__.py.

Step 2: Create a GET endpoint

python
from odoo import http
from odoo.http import request

class ProductApi(http.Controller):

    @http.route('/api/v1/products', type='http', auth='public',
                methods=['GET'], csrf=False)
    def get_products(self, **kwargs):
        user = self._authenticate()
        if not user:
            return request.make_json_response({'error': 'Unauthorized'}, status=401)

        products = request.env['product.product'].with_user(user).search_read(
            [('sale_ok', '=', True)],
            ['id', 'name', 'list_price'],
            limit=50
        )
        return request.make_json_response({'data': products})

Step 3: Create a POST endpoint

python
import json

@http.route('/api/v1/customers', type='http', auth='public',
            methods=['POST'], csrf=False)
def create_customer(self, **kwargs):
    user = self._authenticate()
    if not user:
        return request.make_json_response({'error': 'Unauthorized'}, status=401)

    try:
        payload = json.loads(request.httprequest.data or '{}')
    except ValueError:
        return request.make_json_response({'error': 'Invalid JSON'}, status=400)

    if not payload.get('name'):
        return request.make_json_response({'error': 'name is required'}, status=400)

    partner = request.env['res.partner'].with_user(user).create({
        'name': payload['name'],
        'email': payload.get('email'),
    })
    return request.make_json_response({'id': partner.id}, status=201)

Step 4: Return proper HTTP status codes

Use standard codes so every client understands the result:

  • 200 for a successful read
  • 201 for a successful create
  • 400 for invalid input
  • 401 for missing or wrong credentials
  • 404 when a record is not found

Controller details differ slightly between Odoo versions (for example the route type option), so test each endpoint on your target version.

Secure Your Odoo REST API

An open API is a data leak waiting to happen. Treat security as part of the build, not an afterthought.

Authenticate every request

A simple and safe pattern is to send the user’s API key as a bearer token and check it in the controller:

python
def _authenticate(self):
    header = request.httprequest.headers.get('Authorization', '')
    if not header.startswith('Bearer '):
        return None
    key = header.split(' ', 1)[1]
    uid = request.env['res.users.apikeys']._check_credentials(scope='rpc', key=key)
    return request.env['res.users'].browse(uid) if uid else None

Because the code runs with_user(user), Odoo’s normal access rights and record rules still apply.

Security checklist

  • Use HTTPS only. Never send API keys over plain HTTP.
  • Create a dedicated API user with the minimum access rights it needs.
  • Avoid sudo() unless you have a clear reason, since it bypasses access rules.
  • Validate all input and never build raw SQL from request data.
  • Limit what you return. Send only the fields the client needs.
  • Rotate API keys regularly and revoke unused ones.
  • Add rate limiting at Nginx or your proxy to block abuse.
  • Log requests so you can trace problems and suspicious activity.

Connect Your Odoo REST API to Other Apps

Once your endpoints are live, any tool that can send an HTTP request can use them.

Test with cURL

bash
curl -X GET https://yourcompany.com/api/v1/products \
  -H "Authorization: Bearer YOUR_API_KEY"

Test with Postman as well, so you can save requests and share them with your team.

Common integrations

  • Mobile apps (Flutter, React Native) calling your endpoints for orders, customers and stock
  • Websites and stores (WordPress, Shopify) syncing products and orders
  • Automation tools such as n8n, Zapier or Make for no-code workflows
  • Payment and delivery systems sending status updates through webhooks
  • BI tools such as Power BI or Metabase pulling data for dashboards

Best practices for stable integrations

  • Version your URLs (/api/v1/) so you can improve the API without breaking old clients.
  • Paginate large results using limit and offset.
  • Document every endpoint with its URL, method, parameters and example response.
  • Handle failures gracefully. Return clear error messages and let clients retry safely.

Frequently Asked Questions

Does Odoo have a REST API?

Odoo includes external APIs (XML-RPC and JSON-RPC, with a newer JSON-based API in recent versions) but not a full REST API in older releases. You can build REST-style endpoints yourself with custom controllers.

How do I authenticate with the Odoo API?

Create an API key from your user’s Account Security settings and use it instead of a password. For custom endpoints, send the key in an Authorization header and validate it in your controller.

Is it safe to expose Odoo through an API?

Yes, if you use HTTPS, API keys, a restricted API user, input validation and rate limiting. Never expose endpoints without authentication.

Can I connect Odoo to a mobile app?

Yes. Build custom endpoints for the data your app needs, secure them with API keys or tokens, and call them from your Flutter or React Native app.

Which Odoo versions support custom API endpoints?

Controllers work in all modern Odoo versions, but details such as route types and helper methods change between releases, so always test on your exact version.

Need an Odoo API Built or Integrated?

A well-designed Odoo REST API turns your ERP into a platform that your website, mobile app and other tools can all use. I build custom Odoo APIs, third-party integrations and automation workflows across Odoo versions 8 to 19.

Start your project and tell me which systems you want to connect.