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=”http://www.sap.com/rws/bip“>

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

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

                         <attrname=”auth”

                                            type=”string”

                                            possibilities=”secEnterprise,secLDAP,secWinAD”>authentication</attr>

                         </attrs>’;

     var response;

     var logonToken;

     invocation.open(‘POST’, url, false);

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

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

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

     invocation.send(body);

     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.

  invocation.send(body)

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 = ‘http://vrt0572.bndes.net:6405/biprws/raylight/v1/documents/95075/variables’;

    var docum = new XMLHttpRequest();

    docum.open(‘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);

    docum.send();

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”?>

<variables>

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

<id>L5E</id>

<name>String Fillter </name>

</variable>

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

<id>L5B</id>

<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 = ‘http://vrt0572.bndes.net:6405/biprws/raylight/v1/documents/331140/variables/’+lista[i].innerHTML;

       var docum = new XMLHttpRequest();

       docum.open(‘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);

       docum.send();

      

     }

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

http://vrt0572.bndes.net:6405/biprws/raylight/v1/documents/331140/variables/’variable_id

Which gives me the variables definition :

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

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

<id>L16</id>

<name>V_CONT_PROJETO</name>

<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>

</variable>

     

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

var logoff = new XMLHttpRequest();

var url = ‘http://vrt0572.bndes.net:6405/biprws/logoff’;

logoff.open(‘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);

logoff.send();

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.

Cheers,

Rogerio

To report this post you need to login first.

5 Comments

You must be Logged on to comment or reply to a post.

  1. 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 ;-))

    (0) 
    1. Rogerio Plank 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.

      Cheers,

      Rogerio

      (0) 
      1. Abhi SAP

        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.

         

        Thanks,

        Abhi

        (0) 
        1. Bulent Ozgul

          Hi Abhi,

           

          I’ve just added

           

                  document.write(docum.response);

                  document.write(“</br>”);

           

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

           

          ….

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

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

              {  url = ‘http://vrt0572.bndes.net:6405/biprws/raylight/v1/documents/331140/variables/'+lista%5Bi%5D.innerHTML;

               var docum = new XMLHttpRequest();

               docum.open(‘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);

               docum.send();

               document.write(docum.response);

              document.write(“</br>”);

              }

          ….

          (0) 
  2. 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.

    (0) 

Leave a Reply