Search code examples
reactjsodoo

How to get data from client side with odoo rest api server?


I'm using the rest api odoo server to get content data of a model. I tested on Postman, it works well, enter image description here

but when I integrated into the client side (React app), the request returned an error enter image description here

Plz help me solve this problem, maybe the way to add headers at client side is wrong, I handle at front end like this

  setAuthorization(token) {
    this.httpClient.defaults.headers.common["access_token"] = token;
  }

Solution

  • I've fixed it by the way that I allowed method OPTIONS access into the server to check. Go to main.py from restful module to change it

    @http.route(_routes, type="http", auth="none", methods=["GET", "OPTIONS"], csrf=False, cors='*')