Skip to Content
Author's profile photo Former Member

My tests with Restful API + Javascript – Sample No 1

This blog post is about my experiences using the Raylight Restful API with  Javascript

Guidelines :

I start using the API , trying to acomplish tasks that couldn´t be handled by WEBI alone, without a third party tool.

Examples :

– Using the data from WEBI to render a map;

– Adding another visualizations to the chart set available;

– Automate tasks;

– etc…

Since in my company people outside the IT staff doesn´t have access to development tools, I decided to try Javascript.

You would ask, “okay, you don´t have access to development tools, but what about VBA, since the API will work with any script language capable of doing HTTP requests ?”.

We have another IT restriction which is the port 6405 is disabled for desktop use due to security reasons.

So, Javascript will be.

The first obstacle I found was the lack of documentation in using the API+Javascript .

There´s a very good blog post from Brian Park at

RESTful Web Services SDK

Using it as a start plus some googling, and the strong support from Brian Park,  Anthony MULLER and Ludek Uher I´ve came up with a mehod that works, at least for me and hope it does too to someone else.

I´m using pure Javascript (no AJAX calls nor JQuery). I was able to overcome the CORS problem using a HTTP Request header  ‘X-PINGARUNER’ with the value ‘pingpong’ which allowed me to make the HTTP requests from within an outside WEB Server without running in a security issue (this was tested in IE, Google Chrome and Firefox).

All the tests were made from within my company´s Firewall and the HTTP calls aimed our corporate BO Server.

Before starting with a very simple sample, I would like to address some points :

Pay extremely atention to ‘Content-Type’ and ‘Accept’ request headers (the first is related with the request body of your call – how is the data type of it  – and the former from the response body – in which format  data will be returned).

Stick to the manual to the types. If you receive an internal error

WSR 00999

This is an internal error.

from your call, chances are the types of ‘Content-Type’ or ‘Accept’ are incorrect.

Each time you send a call to request a logon token, you´re logging in the BO Server, and consuming a concurrent session. So, if your code has na error and it halts, without logging off, you will continue connected to the server.

Calling the script again will make you be connected twice. I read somewhere that the timeout to a logon token is 1 hour.

Okay, let´s start with my sample.

The task to be accomplished here is to return the list and definition of the variables in a WEBI doc.

The first thing to do when using the Restful API is to retrieve a logon token which will be used in all subsequente requests.

    var invocation = new XMLHttpRequest();

    var url = ‘http://<server>:6405/biprws/logon/long’;

    var action = ‘logon/long’;

    var body = ‘<?xml version=”1.0″?>

                         <attrs xmlns=”“>

                         <attr name=”userName” type=”string”>user</attr>

                         <attr name=”password” type=”string”>password</attr>





     var response;

     var logonToken;‘POST’, url, false);

     invocation.setRequestHeader(‘X-PINGARUNER’, ‘pingpong’);

     invocation.setRequestHeader(‘Content-Type’, ‘application/xml’);

     invocation.setRequestHeader(‘Accept’, ‘application/xml’);


     token =decodeURI(invocation.getResponseHeader(‘X-SAP-LogonToken’));

What I do here is create na XMLHTTPRequest and set its parameters (url, setRequestHeaders), note in the requestHeaders, the use of the X-PINGARUNER to avoid the security issue and the Content-Type and Accept. Than you call invocation.send which will do the call. Since this request requires data to be sent to the server (user, password and authentication) , this is made passing the variable body (which is the XML containing the data ) to the send method of invocation.


Next step is to retrieve the logon token from the response, this is done by retrieving the response header ‘X-SAP-LogonToken’. This header comes URL encoded, so you have to decode it in order to use it further.

token =decodeURI(invocation.getResponseHeader(‘X-SAP-LogonToken’));

All the requests to a WEBI document are made through the documents id ,which is the unique identifier of a document. In order to find any documents id, go to I Launch PAD , right click on the document and choose Properties . In the bellow Picture, the documents id is highlighted in blue

documens id.png

To get the list of variables in the document with id = 95075

url = ‘’;

    var docum = new XMLHttpRequest();‘GET’, url, false);

    docum.setRequestHeader(‘X-PINGARUNER’, ‘pingpong’);

    docum.setRequestHeader(‘Content-Type’, ‘application/xml’);

    docum.setRequestHeader(‘Accept’, ‘application/xml’);

    docum.setRequestHeader(‘X-SAP-LogonToken’, token);


This request will return, in docum.responseXML the XML document containing the information of the variables in the WEBI document, like this :

<?xml version=”1.0″ encoding=”UTF-8″ standalone=”yes”?>


<variable qualification=”Dimension” dataType=”String”>


<name>String Fillter </name>


<variable qualification=”Dimension” dataType=”String”>


<name>V2_STATUS</name> </variable>

This gives me the listo f variables (name, id and datatype). To get the formula and description of the variables, I´ll have to loop through the list the variables and make another request for each variables in the list :

   var lista = docum.responseXML.getElementsByTagName(‘id’);

    for (i=0;i<lista.length;++i)

    {  url = ‘’+lista[i].innerHTML;

       var docum = new XMLHttpRequest();‘GET’, url, false);

docum.setRequestHeader(‘X-PINGARUNER’, ‘pingpong’);

docum.setRequestHeader(‘Content-Type’, ‘application/xml’);

docum.setRequestHeader(‘Accept’, ‘application/xml’);

docum.setRequestHeader(‘X-SAP-LogonToken’, token);




var lista = docum.responseXML.getElementsByTagName(‘id’) will give the list of variables as a list of XMLNodes, looping through it  I´m abble to get the variable´s id so I can call’variable_id

Which gives me the variables definition :

<?xml version=”1.0″ encoding=”UTF-8″ standalone=”yes”?>

<variable qualification=”Measure” dataType=”Numeric”>



<formulaLanguageId>[V_CONT_PROJETO]</formulaLanguageId> <   <definition>=Contagem([Número Projeto] ParaCada([Consulta 1].[Área OPE];[Depto OPE];[Número Projeto];[V2_SEGMENTACAO_CPCAF]);Tudo)</definition>



The final task is to logoff from the BI platform which is done like this

var logoff = new XMLHttpRequest();

var url = ‘’;‘POST’, url, false);

logoff.setRequestHeader(‘X-PINGARUNER’, ‘pingpong’);

logoff.setRequestHeader(‘Content-Type’, ‘application/xml’);

logoff.setRequestHeader(‘Accept’, ‘application/xml’);

logoff.setRequestHeader(‘X-SAP-LogonToken’, token);


This will end this first blog post. I hope things are clear. Any suggestion, comments or doubts will be much appreciated. I would like to thank Brian Park ,Anthony MULLER  and Ludek Uher as well as the community for its support.



Assigned Tags

      You must be Logged on to comment or reply to a post.
      Author's profile photo Anthony MULLER
      Anthony MULLER

      Hi Rogerio,


      Thanks a lot for sharing your experience!


      The link to Brian Park blog post seems incorrect?


      "Calling the script again will make you be connected twice. I read somewhere that the timeout to a logon token is 1 hour."

      Yes, it is configurable in the CMC.


      Best regards,

      Anthony (my last name is Müller ;-))

      Author's profile photo Former Member
      Former Member
      Blog Post Author

      Hi Anthny,

      thanks on your comment. I´m sorry I misspelled your name .

      I corrected it now.

      I´m intending to write a serie of blog posts with other samples I´m working on.



      Author's profile photo Former Member
      Former Member

      Hi Rogerio,


      Thanks for sharing this awesome blog.


      How do I just show the response body in a html page. Or the xml data which has report output.




      Author's profile photo Bulent Ozgul
      Bulent Ozgul

      Hi Abhi,


      I've just added





      at the end of the loop. the loop looks like :



         var lista = docum.responseXML.getElementsByTagName('id');

          for (i=0;i<lista.length;++i)

          {  url = ''+lista[i].innerHTML;

           var docum = new XMLHttpRequest();

 'GET', url, false);

           docum.setRequestHeader('X-PINGARUNER', 'pingpong');

           docum.setRequestHeader('Content-Type', 'application/xml');

           docum.setRequestHeader('Accept', 'application/xml');

           docum.setRequestHeader('X-SAP-LogonToken', token);






      Author's profile photo Deepak Aswale
      Deepak Aswale

      How do i use the "token" created in the OpenDoc URL, i tried using

      response.sendRedirect("http://server:8080/BOE/OpenDocument/opendoc/openDocument.jsp?sIDType=CUID&iDocID=AY584FeIShxGrETpCwISuOc&token="+ token);

      but it does not work.

      Author's profile photo Kevin Ray
      Kevin Ray

      I know that this post is a few years old.  But I believe it should still work for me.  We are using BI 4.2 SP 7.   So I used the code above to retrieve the logon token.  But when I run the code the header appears to be blank.  I can see the logon token in the response and I can see that a session was created in CMC.  Any ideas on what I did wrong?