Symptom
I am setting up API via a HTML/JS application but there is an error after every request. It works perfectly with Postman but as soon as I paste the Postman code snippet into my application it does not work.
My browser shows the error message:
grey2solidFailed to load https://editor.signavio.com/p/login: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.
What should I do to get the API working with JavaScript?
Resolution
The problem is the interaction of JavaScript application and the used browser. For security reasons, browsers restrict HTTP requests to other domains initiated from within scripts. Your web application is running at one origin (domain) and must have permission to access a server at a different origin (domain). You have to use additional HTTP headers to allow this action.
Please see here for detailed information and code examples:
- https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS
- https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Origin
Keywords
KBA , BPI-SIG-CA-API , REST-API for SAP Signavio , How To