Skip to Content

In this post, you will learn how to combine REST APIs  to build applications. Indeed, I will show you how you can distribute your Webi documents in the cloud (Dropbox here) very easily. The most “painful” step is the authorization one to make sure your data is safe.

Here are the steps to follow:

     1. Creating a Dropbox account

     2. Creating a Dropbox application

     3. Authorizing the application to interact with your Dropbox

     4. Sending the PDF export of a Web Intelligence document to your Dropbox

Creating a Dropbox account

/wp-content/uploads/2015/01/1_618720.png


Then continue with the Free account.

Note: you don’t have to install the Dropbox client on your desktop machine for this tutorial.

Your Dropbox is available here: https://www.dropbox.com/home

/wp-content/uploads/2015/01/2_618721.png


Creating a Dropbox application


This step is necessary since a Dropbox app is mandatory to create interactions between Dropbox and external custom applications.

A Dropbox app can be created from here: https://www.dropbox.com/developers/apps

/wp-content/uploads/2015/01/3_618722.png

Note: Dropbox will send you an email to verify your email address.

Below is a sample of the information requested to create a Dropbox app.

/wp-content/uploads/2015/01/4_618723.png

Note: as Dropbox app name is unique, you must provide a different app name.

Important information here is “App key” and “App secret”. You will need then to authorize your custom application to access to Dropbox account.

/wp-content/uploads/2015/01/5_618724.png

Authorizing your Dropbox app with your Dropbox account


Ok, now you have a Dropbox account and a Dropbox app. To continue this tutorial, you have to link the app with your account. An app can also be linked with other accounts.

To see which Dropbox apps are currently linked with your account, go to the “Settings” section, and click on the “Security” tab. The apps linked are listed at the bottom of the page. Right now, Dropbox indicates that “You haven’t linked any apps”.


The query parameter “client_id” allows you to send the “App key”. The other parameters  “response_type” and “state” are needed respectively to specify the expected response type and to provide a CSFR token (to avoid a cross-request forgery attack). For the purpose of this tutorial, use the provided values.

https://www.dropbox.com/1/oauth2/authorize?client_id= YOUR_APP_KEY&response_type=code&state=KCKSDYPt7b3X0JZsx00DDCxW

/wp-content/uploads/2015/01/6_618725.png

Click “Allow” to accept the link between the Dropbox app and your Dropbox account.

/wp-content/uploads/2015/01/7_618726.png

So, Dropbox will print out an “authorization code”. This code will enable the custom application to interact with Dropbox.

Getting the Access Token


The final step with the Dropbox authentication mechanism (based on OAuth 2.0 protocol) is to transform the “authorization code” to an “access token”. The “access token” can be obtained by a simple REST call to the Dropbox API. You can see bellow how to perform such a call using Azot (no programming skill required).


<call name="GetAccessToken">
                        <request url="https://api.dropbox.com/1/oauth2/token?code=YOUR_AUTHORIZATION_CODE&amp;grant_type=authorization_code" method="POST">
                                               <header name="Accept" value="*/*" />
                                               <header name="Authorization" value="Basic NzQwYTEzcDJ4XXXXXXXXXXXXXXjU5dA==" />
                        </request>
</call>



The difficulty is to provide the correct value into the HTTP header named “Authorization”. This is the couple “appKey:appSecret” encoded in Base64, preceded by “Basic “ keyword.

Although this kind of operation can be done easily in any programming language (“Apache Commons Codec”  in Java), you can do it with this convenient web tool: https://www.base64encode.org/

/wp-content/uploads/2015/01/8_618727.png

Put the encoded value into your HTTP request (replaced in the previous example if you’re using Azot), and run it.

The Dropbox API will send you back a JSON answer:


{"access_token": "l9UASSNZ85MAAAAAABBBFFFVwS0hNQjjALlb0c-VB2lcKhxAV-soAeoPkqVeRj", "token_type": "bearer", "uid": "133078442"}



Ok, now you will be authorized to perform any RESTful call to the Dropbox API using this “access token”.

Note: you will receive an email from Dropbox that informs you of this new connection.

Note: you can see in “App linked” section that the Dropbox app is now authorized. The authorization can be revoked by the user at any time.

Pushing your Web Intelligence document into your Dropbox!

Finally, the harder work is what we have done when we’re dealing with the OAuth authorization mechanism of Dropbox. The rest of the workflow will be quite easy now.

You just have to:

     1.       Logon to BI4 platform, export the Webi document in PDF, and then logoff.

     2.       Send the PDF file to Dropbox.

As a gift for the New Year 2015, I provide you an Azot script for each of these steps.

/wp-content/uploads/2015/01/9_618728.png

So, your document will appear in your Dropbox:

/wp-content/uploads/2015/01/10_618729.png

Enjoy combining many REST APIs to build new applications! In addition, do you know that you can already build such plugins using Web Intelligence UI Extension Points, to add new features to Web Intelligence thanks to your fresh, creative applications?

References:

Web Intelligence REST APIs:

http://help.sap.com/saphelpiis_sbo41sp5wi-sdk/frameset.htm

Dropbox API:

https://www.dropbox.com/developers/core/docs

Cross-site Request Forgery

http://en.wikipedia.org/wiki/Cross-site_request_forgery

Dropbox OAUth – The hard way

https://github.com/smarx/othw

Azot

https://github.com/AnthonyMullerPlayground/azot

Web Intelligence UI Extension Points:

http://scn.sap.com/docs/DOC-59025

To report this post you need to login first.

Be the first to leave a comment

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

Leave a Reply