This article will provide a step-by-step implementation for finding and exporting reports from the SAP BI platform server to your application. The code requires SAP BI platform 4.0 SP05 or later.
You will need to have a valid logon token to use these REST methods. Please read first the server logon article if you have not already implemented it yet.
You can find that article here: https://scn.sap.com/community/restful-sdk/blog/2012/11/17/using-web-intelligence-rest-web-services-t...
Once we have our logon token, we can now access all of the Web Intelligence documents within the BI platform server. In order to export a report, we need to know its document ID and report ID. In this article, we will get these IDs using the REST API.
Getting the document list
To get a list of Web Intelligence documents on the server, we will use the REST method ‘GET’ to the following URI:
URI |
---|
http:// <Server IP> :<port>/biprws/raylight/v1/documents/ |
JavaScript Implementation
Here we use AJAX to send the REST method to the server. We set the “Accept Header” to ‘application/xml’ or ‘application/json’ depending on the format we want. Finally, we set a custom header “X-SAP-LogonToken” to our logon token variable.
Javascript Function |
---|
function getDocs(){ ajaxRequest = $.ajax({url: server + '/biprws/raylight/v1/documents', type: 'get', complete: function(xhr) { json = jQuery.parseJSON(xhr.responseText).documents.document; }, beforeSend: function(xhr) { xhr.setRequestHeader('Accept', 'application/json'); xhr.setRequestHeader('X-SAP-LogonToken', logonToken); } }); } |
C# Implementation
In C#, we first create an HttpWebRequest object which takes the URI as a parameter. Then we set the REST method to ‘GET’, the “Accept Headers” to either ‘application/xml’ or ‘application/json’, and a custom header “X-SAP-LogonToken” to our logontoken variable. Then we create an HttpWebResponse object to collect the server response. Finally, we use the stream class to read the input.
REST Request |
---|
string server = "http://" + IP + ":" + port + "/biprws/raylight/v1/documents"; HttpWebRequest GetRequest = (HttpWebRequest)WebRequest.Create(server); GetRequest.Method = "GET"; GetRequest.Accept = "application/"+dformat; GetRequest.Headers.Set("X-SAP-LogonToken", ltoken); HttpWebResponse GETResponse = (HttpWebResponse)GetRequest.GetResponse(); Stream GETResponseStream = GETResponse.GetResponseStream(); StreamReader sr = new StreamReader(GETResponseStream); Console.WriteLine(sr.ReadToEnd()); |
The server will respond with a list of all documents in XML or JSON format.
Getting the report list
Once we decide on the document, we must also find out which report within that document we want to export.
We do this by using the REST method ‘GET’ to the URI:
URI |
---|
http:// <Server IP> :<port>/biprws/raylight/v1/documents/+ docID +/reports/ |
Be sure to enter the document ID into the URI as shown above.
JavaScript Implementation
Similar to retrieving a document, we set the header to ‘GET’ and the “Accept Header” to either ‘application/xml’ or ‘application/json’, and set a custom header “X-SAP-LogonToken” to our logontoken variable.
Javascript Function |
---|
function listReports(id) { var documentID = id; ajaxRequest = $.ajax({url: server + '/biprws/raylight/v1/documents/'+id+'/reports', type: 'get', complete: function(xhr) { json = jQuery.parseJSON(xhr.responseText).reports.report; }, beforeSend: function(xhr) { xhr.setRequestHeader('Accept', 'application/json'); xhr.setRequestHeader('X-SAP-LogonToken', logonToken); console.log("Requesting a complete list of documents"); } }); } |
C# Implementation
This is very similar to the implementation for retrieving the document list.
REST Request |
---|
string server = "http://" + IP + ":" + port + "/biprws/raylight/v1/documents/" + DocID + "/reports/"; HttpWebRequest GetRequest = (HttpWebRequest)WebRequest.Create(server); GetRequest.Method = "GET"; GetRequest.Accept = "application/"+dformat; GetRequest.Headers.Set("X-SAP-LogonToken", ltoken); HttpWebResponse GETResponse = (HttpWebResponse)GetRequest.GetResponse(); Stream GETResponseStream = GETResponse.GetResponseStream(); StreamReader sr = new StreamReader(GETResponseStream); Console.WriteLine(sr.ReadToEnd()); |
Exporting the report
Finally, we have all the information we need to export the report data. We do this by using the REST method ‘GET’ to the URI:
URI |
---|
http:// <Server IP> :<port>/biprws/raylight/v1/documents/+ docID +/reports/ +reportID |
Again, we need to include the chosen docID and reportID in the above URI.
JavaScript Implementation
The only difference between this code and the two previous examples is that we can set the “Accept Headers” to either ‘text/xml’ or ‘text/html’. If you choose xml, you can store it by using the parseXML method coming from the JQuery library.
Javascript Function |
---|
function exportReport(docId,reportId){ var x = docId; var y = reportId; ajaxRequest = $.ajax({url: server + '/biprws/raylight/v1/documents/'+x+'/reports/'+y, type: 'get', complete: function(xhr) { response = $.parseXML(xhr.responseText); }, beforeSend: function(xhr) { xhr.setRequestHeader('Accept', 'text/xml'); xhr.setRequestHeader('X-SAP-LogonToken', logonToken); } }); } |
C# Implementation
Again, the only differences here are between choosing your response data in either ‘text/xml’ or ’text/html’ formats.
REST Request |
---|
string server = "http://" + IP + ":" + port + "/biprws/raylight/v1/documents/" + CUID + "/reports/" + reportID; HttpWebRequest GetRequest = (HttpWebRequest)WebRequest.Create(server); GetRequest.Method = "GET"; GetRequest.Accept = "text/"+dformat; GetRequest.Headers.Set("X-SAP-LogonToken", ltoken); HttpWebResponse GETResponse = (HttpWebResponse)GetRequest.GetResponse(); Stream GETResponseStream = GETResponse.GetResponseStream(); StreamReader sr = new StreamReader(GETResponseStream); string output = sr.ReadToEnd(); |
The server will respond with the report data in either XML or HTML format depending on whether you set the “Accept Header” to ‘text/html’ or ‘text/xml’, respectively. If you wish to display the report in a browser, then HTML would be your preferred format. On the other hand, if you would like to extract and parse through the report data, then XML format would be your best bet.
With the above implementation, you should be able to export your Web Intelligence data to any application. From there, you can mash it up with other web services data to provide new insights or simply customize it to better suit your business context.
Questions? Comments? Please let me know what you think!
By Brian Park, Product Management Intern, brian.park@sap.com
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
9 | |
8 | |
7 | |
7 | |
5 | |
4 | |
4 | |
4 | |
3 | |
3 |