Skip to Content
Odoo Menu
  • Prisijungti
  • Išbandykite nemokamai
  • Programėlės
    Finansai
    • Apskaita
    • Pateikimas apmokėjimui
    • Sąnaudos
    • Skaičiuoklė (BI)
    • Dokumentai
    • Pasirašymas
    Pardavimai
    • CRM
    • Pardavimai
    • Kasų sistema - Parduotuvė
    • Kasų sistema - Restoranas
    • Prenumeratos
    • Nuoma
    Svetainės
    • Svetainių kūrėjimo įrankis
    • El. Prekyba
    • Internetinis Tinklaraštis
    • Forumas
    • Tiesioginis pokalbis
    • eMokymasis
    Tiekimo grandinė
    • Atsarga
    • Gamyba
    • PLM
    • Įsigijimai
    • Priežiūra
    • Kokybė
    Žmogaus ištekliai
    • Darbuotojai
    • Įdarbinimas
    • Atostogos
    • Įvertinimai
    • Rekomendacijos
    • Transporto priemonės
    Rinkodara
    • Socialinė rinkodara
    • Rinkodara el. paštu
    • SMS rinkodara
    • Renginiai
    • Rinkodaros automatizavimas
    • Apklausos
    Paslaugos
    • Projektas
    • Darbo laiko žiniaraščiai
    • Priežiūros tarnyba
    • Pagalbos tarnyba
    • Planavimas
    • Rezervacijos
    Produktyvumas
    • Diskucija
    • Artificial Intelligence
    • IoT
    • VoIP
    • Žinių biblioteka
    • WhatsApp
    Trečiųjų šalių programos Odoo Studija Odoo debesijos platforma
  • Pramonės šakos
    Mažmeninė prekyba
    • Knygynas
    • Drabužių parduotuvė
    • Baldų parduotuvė
    • Maisto prekių parduotuvė
    • Techninės įrangos parduotuvė
    • Žaislų parduotuvė
    Food & Hospitality
    • Barai ir pub'ai
    • Restoranas
    • Greitasis maistas
    • Guest House
    • Gėrimų platintojas
    • Hotel
    Nekilnojamasis turtas
    • Real Estate Agency
    • Architektūros įmonė
    • Konstrukcija
    • Property Management
    • Sodininkauti
    • Turto savininkų asociacija
    Konsultavimas
    • Accounting Firm
    • Odoo Partneris
    • Marketing Agency
    • Teisinė firma
    • Talentų paieška
    • Auditai & sertifikavimas
    Gamyba
    • Textile
    • Metal
    • Furnitures
    • Maistas
    • Brewery
    • Įmonių dovanos
    Sveikata & Fitnesas
    • Sporto klubas
    • Akinių parduotuvė
    • Fitneso Centras
    • Sveikatos praktikai
    • Vaistinė
    • Kirpėjas
    Trades
    • Handyman
    • IT įranga ir palaikymas
    • Saulės energijos sistemos
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Kiti
    • Nonprofit Organization
    • Aplinkos agentūra
    • Reklaminių stendų nuoma
    • Fotografavimas
    • Dviračių nuoma
    • Programinės įrangos perpardavėjas
    Browse all Industries
  • Bendrija
    Mokykitės
    • Mokomosios medžiagos
    • Dokumentacija
    • Sertifikatai
    • Mokymai
    • Internetinis Tinklaraštis
    • Tinklalaidės
    Skatinkite švietinimą
    • Švietimo programa
    • Scale Up! Verslo žaidimas
    • Aplankykite Odoo
    Gaukite programinę įrangą
    • Atsisiųsti
    • Palyginkite versijas
    • Leidimai
    Bendradarbiauti
    • Github
    • Forumas
    • Renginiai
    • Vertimai
    • Tapkite partneriu
    • Services for Partners
    • Registruokite jūsų apskaitos įmonę
    Gaukite paslaugas
    • Susiraskite partnerį
    • Susirask buhalterį
    • Susitikti su konsultantu
    • Diegimo paslaugos
    • Klientų rekomendavimas
    • Palaikymas
    • Atnaujinimai
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Gaukite demo
  • Kainodara
  • Pagalba
You need to be registered to interact with the community.
All Posts People Badges
Žymos (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Žymos (View all)
odoo accounting v14 pos v15
About this forum
Pagalba

Create Odoo API Endpoint that can be called when run Odoo wilh Multiple DB

Prenumeruoti

Get notified when there's activity on this post

This question has been flagged
17.017
4 Replies
1087 Rodiniai
Portretas
tapm2.odoo

HI,

I see that Odoo has an API Endpoint (web/session/authenticate) that can be called even though the request have no sessionID to specify which DB is using.

Every other Endpoint will return 404 if Odoo have multiple active DB.

I create my own endpoint that copy exactly from web/session/authenticate, but it still return 404.

Does anybody know why and how to fix it.

0
Portretas
Atmesti
Codesphere Tech

Hello,
You have multiple database in system? check odoo.conf for dbfilter parameter..

tapm2.odoo
Autorius

The thing is that the system is required to have multiple active DBs at the same time.

Codesphere Tech

Can you elaborate more about this?

Zehntech Technologies Inc.

Hi,

Thanks for clarifying - this makes the problem much clearer.

You are right, the ?db=mydb parameter alone does not work for anonymous endpoints because Odoo's dispatcher rejects the request with a 404 before it even reads that parameter in a multi-DB setup. The DB selection needs to happen at the dispatcher level, earlier in the request lifecycle.

we have implemented this in a real project.
We built a custom Odoo module for a client who needed anonymous API access across a multi-DB Odoo instance - specifically for a mobile app integration where the calling system had no session context. The setup involved:

A custom ir.http override to intercept the DB name from a request header (X-Odoo-Database) before Odoo's dispatcher rejected the request
All custom endpoints decorated with auth='none' and routed outside the standard session-based flow
A lightweight token validation layer inside the endpoint itself (since there is no Odoo session, you handle your own auth logic)

It worked reliably in production on a 3-DB Odoo 16 instance.

Here is the approach that works for you:
Override _pre_dispatch in ir.http
In your custom module, extend ir.http and override the _pre_dispatch (or _get_default_session depending on your Odoo version) to read the database name from the request early - before routing resolves:

from odoo import models
from odoo.http import request, db_filter

class IrHttp(models.AbstractModel):
_inherit = 'ir.http'

@classmethod
def _pre_dispatch(cls, rule, args):
# Read ?db= param or X-Odoo-Database header early
db = (
request.httprequest.args.get('db')
or request.httprequest.headers.get('X-Odoo-Database')
)
if db and db in db_filter([db]):
request.session.db = db
return super()._pre_dispatch(rule, args)

--------------------------------------------------------------------------------------------------
Then your custom route should be decorated like this:

@http.route('/api/custom/do-something',
type='json',
auth='none', # critical
csrf=False,
save_session=False)
def do_something(self, **kwargs):
...
________________________________________________________________________________________________________
A few important notes:

- The auth='none' is mandatory - auth='public' will still try to resolve a user session which requires a DB context.
- Make sure your endpoint does not touch any ORM or recordset at the point of entry before the DB is set.
- If you are on Odoo 16+, the dispatcher was refactored - let us know your version and we can adjust the override accordingly.

This pattern has been implemented for similar anonymous API gateway scenarios and works reliably in multi-DB setups.
Hope this works for you! Feel free to reach out for further discussion.

Regards,
santosh.sekwadia@zehntech.com

tapm2.odoo
Autorius

Thanks a lot for the answer. I get the idea now. I'm using Odoo17 so the dispatcher behaves differently now.

Portretas
Zehntech Technologies Inc.
Best Answer

Hello, 

This behavior is expected in Odoo when running with multiple databases.

The /web/session/authenticate endpoint works without specifying a DB because it is explicitly designed as a public, pre-database selection route. Most other endpoints (including custom ones) require a database context, otherwise Odoo cannot determine which DB to route the request to, resulting in a 404.

Simply copying the controller logic is not enough, as Odoo internally treats such routes differently (e.g., using auth="none" and special dispatch handling).

Possible approaches:

  • Pass the db parameter explicitly in your API request
  • Use a subdomain or routing mechanism to map requests to a specific database
  • Customize the request dispatching (advanced) to handle DB selection before your endpoint is called

Hope this works for you! If you need any help implementing this or want a more optimized approach, feel free to reach out for further discussion

Regards,

Zehntech Technologies Inc.

santosh.sekwadia@zehntech.com

0
Portretas
Atmesti
tapm2.odoo
Autorius

Hi. Thank you for your answers. I want to make my requirements clearer if it helps.

- I create a custom API Endpoint on Odoo. Ex: /api/custom/do-something
- If my Odoo is having multiple DB: call that API as an anonymous user will return 404.

I think your 3rd approach (Customize the request dispatching (advanced) to handle DB selection before your endpoint is called ) is what I looking for. But i have tried called /api/custom/do-something?db=mydb anonymously, it still returns 404.

Have you guys ever implemented something that can solve or workaround this problem?

Thanks

tapm2.odoo
Autorius

Zehntech comment worked for me.

Odoobot
On leave today.
Portretas
Ali Khalid
Best Answer

You're spot on ?db=mydb gets rejected by Odoo's root dispatcher before your /api/custom/do-something even loads in multi-DB setups. Been there!

What works for me:

  • Server-wide module: server_wide_modules = web,base,your_module in odoo.conf. Restart and it matches /web/session/authenticate behavior.

  • Quick ir.http override:

  • python

from odoo import http

class IrHttp(http.Controller):

    @classmethod

    def _authenticate(cls, endpoint, ...):

        db = request.httprequest.args.get('db')

        if db: request.session.db = db

  •         return super()._authenticate(...)

  • Then route: @http.route('/api/custom/<string:db>/do-something', auth='none')

Easy alternative: Just use XML-RPC /xmlrpc/2/db. It handles db params flawlessly.

0
Portretas
Atmesti
Portretas
Bloopark systems GmbH & Co. KG, Bloopark systems GmbH & Co. KG
Best Answer
Hi,
First of all, Odoo relies on the existing request session.
You can see it here https://github.com/odoo/odoo/blob/17.0/addons/web/controllers/session.py#L26
It means that Odoo to now that request.session.db already point to the target DB

Second point, in authenticate() route, you can see that it uses explicit db parameter passed by the client
https://github.com/odoo/odoo/blob/17.0/addons/web/controllers/session.py#L30C9-L30C21
and then force creation of DB environment, before passing it to session.info
https://github.com/odoo/odoo/blob/17.0/addons/web/controllers/session.py#L42-L51

It means that in a same session you can not access 2 DB simultaniously
  • using browser, you need to change DB
  • using API, you need to pass specific DB name at session (only that one will allow to access many DB at same time) as for each call you will pass a specific session

Hope it helps

0
Portretas
Atmesti
Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Registracija
Related Posts Replies Rodiniai Veikla
in POS orderline is it possible to add background color to the discounted product line
17.0
Portretas
Portretas
1
lapkr. 25
1523
Odoo 17 Pos Js development
17.0
Portretas
Portretas
1
rugp. 25
3847
How can I make the cost field on products readonly? Solved
17.0
Portretas
Portretas
Portretas
2
rugp. 25
2246
Odoo 17 one2many lines issue
17
Portretas
Portretas
Portretas
Portretas
3
birž. 25
4643
Change resume view Solved
17
Portretas
Portretas
Portretas
Portretas
4
liep. 25
2756
Bendrija
  • Mokomosios medžiagos
  • Dokumentacija
  • Forumas
Atvirasis kodas
  • Atsisiųsti
  • Github
  • Runbot
  • Vertimai
Paslaugos
  • Odoo.sh talpinimas
  • Palaikymas
  • Atnaujinti
  • Pritaikytas programavimo kūrimas
  • Švietimas
  • Susirask buhalterį
  • Susiraskite partnerį
  • Tapkite partneriu
Apie mus
  • Mūsų įmonė
  • Prekės ženklo turtas
  • Susisiekite su mumis
  • Darbo pasiūlymai
  • Renginiai
  • Tinklalaidės
  • Internetinis Tinklaraštis
  • Klientai
  • Teisinis • Privatumas
  • Saugumas
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk Slovenščina Español (América Latina) Español Svenska ภาษาไทย Türkçe українська Tiếng Việt

Odoo yra atvirojo kodo verslo programų rinkinys, kuris apima visas įmonės poreikius: CRM, El. Prekybą, Apskaitą, Atsargų, Kasų sistemą, Projektų valdymą ir kt.

Unikali Odoo vertės pasiūla – būti tuo pačiu metu labai lengvai naudojama ir visiškai integruota sistema.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now