Hi,
When I try to retrieve a list of infostore objects using the Rest API (http://localhost:6405/biprws/infostore) everything works fine.
But when I try to retrieve a list of universes (http://localhost:6405/biprws/sl/v1/universes) using the same code I get the following error:
ERROR: 401 - Unauthorized - WSR 00002 - Incorrect session found in HTTP header X-SAP-LogonToken (too many values) error
In my code the X-SAP-LogonToken has been surrounded by double-quotes:
xhrObj.setRequestHeader("X-SAP-LogonToken",sessionToken);
Does anyone know what I'm doing wrong?
Here is the full code:
<!DOCTYPE html><html><head> <script src="scripts/jquery-1.11.3.js"></script> <script src="scripts/jquery.json2html.js" type="text/javascript"></script> <script> var nextRequestAttemptDelay=700; //set this value for longer time if many of requests fail-milliseconds var sessionToken; var boServer; function login() { console.log("logOn"); boServer="http://localhost:6405"; //new logon object var logonInfo = new Object(); //for BO login there are 3 attributes essential for logging: userName,password and auth. logonInfo.userName="enter user"; logonInfo.password="enter password"; logonInfo.auth="secEnterprise"; //#biprws/logon/long var logonUrl="http://localhost:6405/biprws/logon/long"; console.log("URL: " + logonUrl); //#for log var inputData = JSON.stringify(logonInfo,null,'\t'); // call request to BO to perform query and log inging we will use JSON. Simply because it is clearer than XML // convert JS objects to JSON string with input data... var queryResult=performQuery(inputData,'POST',logonUrl); // if query was successfull if (queryResult.errText==null){ //set global session token sessionToken=queryResult.data.logonToken; console.log("You are now logged in! ","success"); setTimeout( function(){ loadMainInfostoreView(); } ,500 ); } else{ //there was an erro while processing request console.log("Logging to BOBJ server has failed - "+queryResult.errText ,"error"); } } function loadMainInfostoreView() { setTimeout( function(){ //var infostoreUrl="http://localhost:6405/biprws/infostore"; var infostoreUrl="http://localhost:6405/biprws/sl/v1/universes" //no input data required // call request to BO to perform query for getting infostore data var queryResult=performQuery(null ,'GET',infostoreUrl); // if query was successfull if (queryResult.errText==null){ //show results showResults('INFOSTORE_LIST',queryResult.data.entries) } else{ //there was an erro while processing request //inform user about error during logg-in process.. console.log("ERROR: Loading main infostore view has failed - "+queryResult.errText ,"error"); } } ,300 ); } function performQuery(inputData,requestType,requestUrl){ // result object var result = new Object(); result.data=null; //for result data result.errText=null; //for result error message //console.log("performing query"); $.ajax({ beforeSend: function(xhrObj){ //xhrObj.setRequestHeader("Content-Type","application/json"); xhrObj.setRequestHeader("Accept","application/json"); //if session exists it is neccessary to add it into any request if (sessionToken != null){ xhrObj.setRequestHeader("X-SAP-LogonToken",sessionToken); } }, //if input data exists we want to add it async: false, //otherwise function would be always null crossDomain:true, data: inputData, type: requestType, url: requestUrl, dataType: 'json', contentType:'application/json', error: function(xhrObj, textStatus, errorThrown) { // sometimes we get only HTTP OK 200 status without {} and jquery incorrectly ¨ //interpretes that as an error state so we want // check for client 4xx and server 5XX error codes if (xhrObj.status>=400){ //if there is no response at all.. if (textStatus=="error" && errorThrown==""){ errorThrown="No response from server"; } var d=" - "; var errObj = new Object(); // try enhanced error description try { errObj=JSON.parse(xhrObj.responseText.replace(/\n/g,"")); // remove new lines from response string result.errText=xhrObj.status+d+errorThrown +d+errObj.error_code+d+errObj.message; //otherwise at least some description } catch (err) { result.errText=xhrObj.status+d+errorThrown; } } }, success: function(xhrObj, textStatus, errorThrown) { //manage non error but still unsuccessful requests result.data=xhrObj; }, }); return result } function showResults(actionType,actionData){ switch(actionType){ case "INFOSTORE_LIST": // for infostore base view we create menu items // create menu $.each(actionData,function(key,value){ //create menu button and its label console.log("data: " + key + " - " + value.name) }); } } </script></head><body><button onclick="loadMainInfostoreView()">Click me</button></body><script> $( document ).ready(function() { console.log( "ready!" ); login(); });</script></html>