Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

165
Visualizações
React Native call Odoo API via Axios struggling with CORS

I am using React Native, and trying to call Odoo APIs using Axios.

This is how I successfully call authenticate on my local Odoo instance.

const authenticate = await axios.post('http://localhost:8069/web/session/authenticate',
    {
        params: {
            db: 'db',
            login: 'odoo',
            password: 'odoo',
        }
    }
);

Now that I got the result from Odoo. I want to call methods and query some records.

So, I tried to get some records from DataSet search_read first.

Here is what I tried.

const search_read = await axios.post('http://localhost:8069/web/dataset/search_read',
    {
        params: {
            model: 'stock.picking',
            fields: ['id','name'],
        }
    }
);

It gave me this error.

Access to XMLHttpRequest at 'http://localhost:8069/web/dataset/search_read' from origin 'http://localhost:19006' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

Even though I already inherited and customized both @http.route to allow CORS in the Odoo side.

from odoo.addons.web.controllers.main import Session, DataSet
from odoo import http


class SessionInherit(Session):

    @http.route('/web/session/authenticate', type='json', auth="none", cors='*')
    def authenticate(self, db, login, password, base_location=None):
        return super(SessionInherit, self).authenticate(db, login, password, base_location)

    
class DataSetInherit(DataSet):

    @http.route('/web/dataset/search_read', type='json', auth="user", cors='*')
    def search_read(self, model, fields=False, offset=0, limit=False, domain=None, sort=None):
        return super(DataSetInherit, self).search_read(model, fields, offset, limit, domain, sort)

How do I solve this problem?

Note: The authentication request also had CORS problem before I customized the authenticate method to allow it. Once I did, it works fine. However, when I do the same for search_read, it still gives me CORS error.

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda