Skip to content

mamurshe/PowerBI.Api.Client

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

70 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PowerBI.Api.Client

C# Client library to deal with PowerBI REST Api : MSDN DOCUMENTATION

Check out the article on TechNet Wiki : TechNet Wiki - PowerBI API in .Net

Installation

/!\ Take care

Version 1.1 is obsolete. Please read the wiki page for v1.2 alpha : https://github.com/Vtek/PowerBI.Api.Client/wiki/Version-1.2-alpha

PM> Install-Package PowerBI.Api.Client -Pre

Features

  • Automatic OAuth2 authentication
  • Datasets listing
  • Datasets & tables creation
  • Insert data into tables
  • Clean data from tables

Getting started

To configure the PowerBI Api Client you can use the configuration section. Just add it to the .config :

<?xml version="1.0" encoding="utf-8"?>
<configuration>
	<configSections>
		<section name="PowerBIConfiguration" type="PowerBI.Api.Client.Configuration.PowerBIConfiguration, PowerBI.Api.Client, Version=1.0.0.0"/>
	</configSections>
	<PowerBIConfiguration>
	    <OAuth
	      Authority="https://login.windows.net/common/oauth2/authorize" 
	      Resource="https://analysis.windows.net/powerbi/api"
	      Client="MyClientId" 
      	  User="MyUserName" 
      	  Password="MyPassword"/>
	    <Api 
	      Url="https://api.powerbi.com/v1.0/myorg" />
	  </PowerBIConfiguration>
</configuration>

You can also initialize the configuration by code (The configuration section is use by default if Initialize is not call) :

PowerBIClient.Initialize("myUrl", "myAuthority", "myResource", "myClient", "myUser", "myPassword");

It is possible to get a configuration object :

var configuration = PowerBIClient.GetConfiguration("myUrl", "myAuthority", "myResource", "myClient", "myUser", "myPassword");

The client is now ready. It's easy to use, call the Do method of PowerBIClient class to define an action which uses an authenticated instance.

PowerBIClient.Do(api => {

});

If you want to use a configuration object call Do method with the configuration instance :

PowerBIClient.Do(configuration, api => {

});

Asynchronous call are avaible in 1.2 version :

await PowerBIClient.DoAsync(api => {

});

Api methods

Get all Datasets

PowerBIClient.Do(api => {
	var datasets = api.GetDatasets();
});

Get Dataset identifier by name

PowerBIClient.Do(api => {
	var datasetId = api.GetDatasetId("myDatasetName");
});

Check if a name matches with a registered Dataset

PowerBIClient.Do(api => {
	var isDatasetExist = api.IsDatasetExist("myDatasetName");
});

Check if an identifier matches with a registered Dataset

PowerBIClient.Do(api => {
	var isDatasetIdExist = api.IsDatasetIdExist("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX");
});

Create a Dataset and its related tables

PowerBIClient.Do(api => {
	var isCreated = api.CreateDataset("myDatasetName", typeof(MyObject1), typeof(MyObject2), ...);
});

Get groups

PowerBIClient.Do(api => {
	var datasets = api.GetGroups();
});

List tables

PowerBIClient.Do(api => {
	var tables = api.GetTables("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX");
});

Update a table

PowerBIClient.Do(api => {
	var isCreated = api.UpdateTable("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX", "myTableName", typeof(MyObject1));
});

Insert a data into a table

PowerBIClient.Do(api => {
	var isObjectInsert = api.Insert("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX", new MyObject1
	{
		DateTimeProp = DateTime.Now,
		IntProp = 1,
		BooleanProp = true,
		StringProp = "a string !",
		DoubleProp = 1.1
	});
});

Insert a list of data into a table

PowerBIClient.Do(api => {
	var isListInsert = api.InsertAll("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX", new List<object>
	{
		new MyObject1
		{
			DateTimeProp = DateTime.Now,
			IntProp = 1,
			BooleanProp = true,
			StringProp = "a string !",
			DoubleProp = 1.1
		},
		new MyObject1
		{
			DateTimeProp = DateTime.Now,
			IntProp = 2,
			BooleanProp = false,
			StringProp = "a string !",
			DoubleProp = 2.1
		}
	});
});

Clean a table

PowerBIClient.Do(api => {
	var isDelete = api.Delete<Product>("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX");
});

##PowerBI.Api.Client with Xamarin A PCL version exists for use PowerBI Api on Xamarin.iOS & Xamarin.Forms (Android come soon). This version is unstable, for more informations check the wiki page : PCL. More documenation on this part available soon !

Licence

The MIT License (MIT)

Copyright (c) 2015 Sylvain PONTOREAU ([email protected])

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Releases

No releases published

Packages

No packages published

Languages

  • C# 100.0%