Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

318
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!