Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Removed translated content for 'zh'
Sv translation
languageen

With this tutorial we aim to show you how to build .NET application using BellaDati analytics features through REST API. Main focus is on

      • OAuth authentication with BellaDati using xAuth method
      • BellaDati REST API calls
      • Processing of REST API (JSON and non-JSON format) 
      • Handling of BellaDati HTTP errors

We will use C# programming language to allow us to experiment lavishly with our code. 

Tutorial pre-requisites are

      • BellaDati application installed on your machine or cloud (min.version 2.7.15.3)
      • REST API enabled in your BellaDati application's domain
      • BellaDati data warehouse should contain at least 3 datasets and reports in your domain
      • Visual Studio for programming in C#

 

Firstly, we need to create a project in Visual Studio. It is WPF app in ourexample.

 

Paste the BellaDatiBase.cs and BellaDatiConnection.cs to your solution.

After that, you can start with writing a code to the MainWindow.xaml.cs. And you can create your xaml, base to your fantasy.

1. Obtain accessToken from BellaDati REST API

Appropriate BellaDati endpoint for getting the oauth_access_token is defined as follows:

Code Block
themeMidnight
languagec#
public const string XAUTH_ACCESS_TOKEN = "/oauth/accessToken";

 

This oauth_access_token is required for all consequent calls against BellaDati Platform. It is implemented in BellaDatiConnection.cs.

In this example, let's assume that we have set up a domain with a consumer key mykey and a consumer secret apisecret. These keys set up to your App.config see below.

Code Block
themeMidnight
languagec#
<appSettings>
    <add key="consumerKey" value="mykey"/>
    <add key="consumerSecret" value="apisecret"/>
</appSettings>

Now you can connect to our server and authenticate:

Code Block
themeMidnight
languagec#
BellaDatiConnection connection = new BellaDatiConnection("https://service.belladati.com");
connection.xAuthGetAccessToken(textBoxName.Text, pswdBox.Password);

2. Access REST API using HTTP GET method

After the authentication you have an oauth_access_token and you can access all available protected REST API resources, e.g. GET reports, dashboards, views etc. Here is an example for GET Reports. All REST API you can find under REST API Resources.

 

Code Block
themeMidnight
languagec#
titleCall function doGet(url) from your created instance connection.
string data = connection.doGet("/api/reports");

 

If you have some created report, this function will return data from REST API in JSON see below.

 

We recommend to surround the function connection.doGet with try catch clause as shown in example below.

Code Block
themeMidnight
languagec#
 	try
    {
      connection.xAuthGetAccessToken(textBoxName.Text, pswdBox.Password);
      string data = connection.doGet("/api/reports/47685");
      textBlockResponse.Text = data;
    }
	catch (Exception ee)
    {
      textBlockResponse.Text = ee.Message;
    }

 

So If there is some error you will see it in some error box.

As a next step, you can display some chart as image:

Code Block
themeMidnight
languagec#
string data = connection.doGet("/api/reports/views/47685-XtFJ2yl9DX/image");

The response of this REST API is png image. It will save it to chart.png and than you can load it to you pictureBox see below.

Code Block
themeMidnight
languagec#
  var uri = new Uri(@"chart.png");
  var bitmap = new BitmapImage(uri);
  pictureBox.Source = bitmap;
    
Info

If you want to change the path of image, you can do it in class BellaDatiConnection.

 

 

 

The whole example includes the classes you need...

Sv translation
languageja

このチュートリアルでは、REST APIを介してBellaDati分析機能を使用して.NETアプリケーションを構築する方法をお見せすることを目指しています。主な焦点は:

  • BellaDatiがXAUTH法を用いたOAuth認証
  • BellaDati REST API呼び出し
  • RESTAPI処理(JSONと非JSONフォーマット)
  • BellaDatiHTTPエラーの取り扱い

私たちは私たちのコードで贅沢に試すことができるようにC#プログラミング言語を使用します。

チュートリアルの前提条件は

    • BellaDatiアプリケーションがあなたのマシンまたはクラウド上にインストールされました。(min.version 2.7.15.3)
    • REST APIはあなたのBellaDatiアプリケーションドメインで有効になります。
    • BellaDatiデータウェアハウスは、ドメイン内に少なくとも3つのデータセットとレポートが含まれる必要があります。
    • C#でのプログラミング用Visual Studio 

 

まず、Visual Studioでプロジェクトを作成します。私達の例にWPFアプリです。

 

あなたのソリューションにBellaDatiBase.csとBellaDatiConnection.csを貼り付けます。

その後、MainWindow.xaml.cs.へのコードを書き込んで始めます。あなたの創造によりXamlを作成できます。

1.  BellaDati REST APIからaccessTokenを取得すること

次のようにoauth_access_tokenを取得するための適切なBellaDatiエンドポイントが定義されます。

Code Block
themeMidnight
languagec#
public const string XAUTH_ACCESS_TOKEN = "/oauth/accessToken";

 

このoauth_access_tokenBellaDatiプラットフォームに対してすべての必然的な呼び出しのために必要とされます。それはBellaDatiConnection.csに実装されます。

この例では、我々はコンシューマキーにmykeyとコンシューマシークレットapisecretAPIでドメインを設定していると仮定しましょう。これらのキーがあなたのApp.configファイルに設定します。以下を参照してください。

Code Block
themeMidnight
languagec#
<appSettings>
    <add key="consumerKey" value="mykey"/>
    <add key="consumerSecret" value="apisecret"/>
</appSettings>

今、あなたは私たちのサーバに接続し、認証できます。

Code Block
themeMidnight
languagec#
BellaDatiConnection connection = new BellaDatiConnection("https://service.belladati.com");
connection.xAuthGetAccessToken(textBoxName.Text, pswdBox.Password);

2. HTTP GET方法を使用ことでREST APIをアクセス

認証後は、oauth_access_tokenを持って、GETレポート、ダッシュボード、ビューなど使用可能なすべての保護されたREST APIのリソースにアクセスできます。、。ここではGET Reportsについての例です。REST API Resourcesの下にすべてREST APIを見つけます。

 

Code Block
themeMidnight
languagec#
titleCall function doGet(url) from your created instance connection.
string data = connection.doGet("/api/reports");

 

いくつか作成されたレポートを持っている場合、この関数は以下のようにJSONでのREST APIからデータを返却します。

 

私たちは、次の例に示すようにtry catch句を持つconnection.doGet関数を囲むようにお勧めします。

Code Block
themeMidnight
languagec#
 	try
    {
      connection.xAuthGetAccessToken(textBoxName.Text, pswdBox.Password);
      string data = connection.doGet("/api/reports/47685");
      textBlockResponse.Text = data;
    }
	catch (Exception ee)
    {
      textBlockResponse.Text = ee.Message;
    }

 

エラーがあれば、いくつかのエラーボックスに表示されます。

次のステップとして、あなたは画像のようないくつかのチャートを表示できます:

Code Block
themeMidnight
languagec#
string data = connection.doGet("/api/reports/views/47685-XtFJ2yl9DX/image");

このRESTAPIのレスポンスは、PNG画像です。それはchart.pngに保存されて、それをPictureBoxにロードできます。 

Code Block
themeMidnight
languagec#
  var uri = new Uri(@"chart.png");
  var bitmap = new BitmapImage(uri);
  pictureBox.Source = bitmap;
    
Info

イメージのパスを変更したい場合、BellaDatiConnectionクラスでそれを行うことができます。

 

 

 

全体のでは、あなたがほしいクラスが含まれます。

REST APIはあなたのBellaDatiアプリケーションドメインで有効になる