GithubHelp home page GithubHelp logo

powerbi.api.client's Introduction

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.

powerbi.api.client's People

Contributors

spontoreau avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

powerbi.api.client's Issues

Error on : {"AADSTS65001: No permission to access user information is configured for '...' application, or it is expired or revoked.

Hi Sylvain , thanks for the package, very cool.

We were trying to change some PowerBI API samples to use the package, but getting this error:
Error on : {"AADSTS65001: No permission to access user information is configured for '...' application, or it is expired or revoked.
at Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext.RunAsyncTask[T](Task`1 task)
at Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext.AcquireToken(String resource, String clientId, UserCredential userCredential)
at PowerBI.Api.Client.PowerBIClient.Authenticate() in c:\Users\joana.barbosa\Downloads\PowerBI.Api.Client-master\PowerBI.Api.Client-master\src\PowerBI.Api.Client\PowerBIClient.cs: line 110

We can get the token using the standard oauth login/authorize app popup (we are using powerbi getting started sample from Josh Kaplan, works fine) but not using the user/password (silent usercredential ?). What am I missing?

In azure the app is created as Native client application with PowerBI Service delegated Permissions (all three permissions) and also Azure AD default permission: enable sso and read user profiles.

-tried creating another azure app just in case, same error
-validated credentials are working ok, forcing an incorrect password return expected invalid login

Thanks!
Rui

image

image

PCL documentation

It will be better to have a more complet documentation for PCL version

Asynchronous call

It will be better to have the choice between asynchronous and synchronous call on the Api :)

Support for Multi-tenant web application / application with configuration from a database.

We would like to use your library for both our online multitenant solution, however with a static constructor reading from a config file this wouldn't support having one application writing to different PowerBI users.

Additionally in our onsite application we have one database where we keep our configuration, saving powerBI configuration in the database is alot more convinient than maintaining local configuration files or having our application write these.

PCL version of the library

The solution need a specific project for the PCL version.
Configuration object need to be change in simple DTO for this version.

Traditionnal OAuth flows

Set the User/Password in the configuration section must be optionnal.
If this informations aren't set, the Traditionnal flows must be used (Login UI to connect on AAD).

Table operations

The library must implements :

  • List of tables
  • Update a table schema

Authentication - client_secret missing?

Hi Sylvain,
Thank you for sharing this package, has really helped me out.
I was wondering if you had any experience with the below issue when using the package - I made sure my user/password info is correct in Web.Config, and on Azure Active Directory the app had full access (as you showed in one of the other Issues Threads), but it doesn't seem like that's the issue -- seems the OAuth "client_secret" (i.e. the password?) is missing?

"{"Message":"An error has occurred.","ExceptionMessage":"AADSTS90014: The request body must contain the following parameter: 'client_secret or client_assertion'.\r\nTrace ID: 17dca2cd-f0d9-4dff-bddc-12513ec9d55a\r\nCorrelation ID: 365cd5d2-bd86-4a0b-b4d1-587fc3c8226e\r\nTimestamp: 2015-04-22 10:24:10Z","ExceptionType":"Microsoft.IdentityModel.Clients.ActiveDirectory.AdalServiceException","StackTrace":" at Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext.RunAsyncTask[T](Task1 task)\r\n at Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext.AcquireToken(String resource, String clientId, UserCredential userCredential)\r\n at PowerBI.Api.Client.PowerBIClient.Authenticate()\r\n at PowerBI.Api.Client.PowerBIClient.Do[T](Func2 function)

Thank you for your help!!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.