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

319
Visualizações
Axios request to odoo Api

I want to make a frontend with vue with odoo as the backend. But everytime i make a request via axios to odoo i get a CORS Error.

Following are two Controller methods in odoo.

@http.route('/login', type='json', auth='none', cors='http://127.0.0.1:5173', csrf=False, methods=['OPTIONS', 'POST'])
def login(self, db, login, password):
    http.request.session.authenticate(db, login, password)
    return http.request.env['ir.http'].session_info()

@http.route('/logout', type='json', auth='user', cors='http://127.0.0.1:5173', csrf=False, methods=['OPTIONS', 'POST'])
def logout(self):
    return {'test'}
    http.request.session.logout()

The code for the request in JS is the following

async function login() {
    axios.post('http://127.0.0.1:8069/login', {
        jsonrpc: "2.0",
        params: {
            db: "db_name",
            login: email.value,
            password: password.value
        },
    }, {
        headers: {"content-type": "application/json"},
        withCredentials: true,
    })
    .then(content => {
        console.log(content.data)
    })
    .catch(error => alert(error))
    }

async function logout() {
    axios.post('http://127.0.0.1:8069/logout', {
        "jsonrpc": "2.0",
        "params": {}
    }, {
        withCredentials: true,
        headers: {"Content-Type": "application/json"},
    })
    .then(content => {
        console.log(content.data)
    })
    .catch(error => alert(error))
}

When i take the cors out of the controller methods i get the error

Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

When cors='*' and withCredentials=true then

The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*' when the request's credentials mode is 'include'.

Login works when withCredentials is false and cors='*' or cors the ip. When it's true i get the following error

The value of the 'Access-Control-Allow-Credentials' header in the response is '' which must be 'true' when the request's credentials mode is 'include'.

Logout never works. Everytime there is a cors error. For example:

Response to preflight request doesn't pass access control check: Redirect is not allowed for a preflight request.

What am i missing? How do i call the odoo api the right way?

about 4 years ago · Santiago Trujillo
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