Frequent Visitor.

Get “401 Unauthorized“ error code when consume OO REST API through JavaScript code, need help

Get “401 Unauthorized“ error code when consume OO REST API through JavaScript code. I am using OO version 10.70.  Is there any sample JavaScript code to demonstrate how to consume OO by using javaScript? Thanks in advance.

Error message:

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



REST API request was sent from a Chrome web browser, where CORS (Cross-Origin Resource Sharing)  has been eabled. 

This is the source code of javaScript embedded in a web page, where user name and password was replaced with working one.  HTTP header with the authentication information was sent to OO REST through jQuery's "beforeSend" callback  function. 

The OO REST API has been tested through SOAPUI and get expected result. 


Comparing the header message sending from SoapUI, and from Chrome web browser, there were two main difference that I can find:

 1.  "GET' method was used at SoapUI, while "OPTIONS" was used at Chrome web browser

  2.  "Authorization: Basic **"  header was added at SoapUI.


Snapshot of request header and response header for debuggging was attached.





1 Reply
Frequent Visitor.

Figured it out.  Send API request from server side instead of client side. 

The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.