Skip to Content
Menu
This question has been flagged
1 Reply
3366 Views

I am encountering a CORS (Cross-Origin Resource Sharing) error when making a POST request to an API endpoint in Odoo from a web page. The error occurs when the browser attempts to send data to the endpoint, while the request works fine using tools like Postman. The browser’s console shows a CORS error indicating that the request is blocked due to missing or incorrect CORS headers. Despite including headers like Content-Type: application/json  the issue persists. The Odoo server logs indicate that an OPTIONS request is sent before the POST request, which is typical for preflight requests to check CORS permissions. However, the server-side configuration may not be set up to handle these OPTIONS requests correctly.
This is my route 

@http.route('/api/create_employee', type='json', auth='none', methods=['POST'], csrf=False, cors='*')

This is my header 

response = request.make_response(
json.dumps({'message': 'Employee created successfully'}),
headers={
'Access-Control-Allow-Origin': '*', # Adjust to restrict access as needed
'Access-Control-Allow-Methods': 'POST, GET, OPTIONS',
'Access-Control-Allow-Headers': 'Origin, Content-Type, Accept, Authorization, talview-odoo-api',
'Access-Control-Allow-Credentials': 'true',
"Content-Type": "application/json"
}
)
return response


Thank you in advance for your help!


Avatar
Discard
Best Answer

Hi, did you find a solution?

Avatar
Discard
Related Posts Replies Views Activity
1
May 25
1096
1
Mar 24
1117
0
Sep 23
8014
1
Jun 25
1592
1
Jun 25
558