Integrate Power BI into Your Application: Part 5 – Data Source Management


New REST API of Power BI is revolutionary. In addition to embedding content in Power BI, ability to refresh data set from API, it also gives you many functions to work with Gateways and Data Sources. With this API, you can set up new data sources, clone data sets, check the credentials of a data source, get list of all data sources under a gateway, and do many other operations. In other words; Data source management can be fully automated with REST API. Continue reading this post if you like to learn more about this.  If you like to learn more about Power BI; read Power BI book; from Rookie to Rock Star.

Step 1: Register your Application

Step 2: Authenticate

Sample Code

The sample code for this example can be downloaded from here.

Get List of Gateways

List of gateways are accessible through a function under Gateways, called GetGatewaysAsync. you can easly fetch list of gateways (on-premises gateways, not personal), and then loop through these.

var gateways = await client.Gateways.GetGatewaysAsync();


This function as you can see in above code screenshot will give you list of all on-premises data gateways defined under your account. then you can loop through each gateway and get the information of that gateway, for example; name of the gateway, Id of it, and some information such as version.

Here are list of gateways under this Power BI account;


As you can see all of above gateways can be accessed through REST API.

Get List of Data Sources

Under a gateway, you can access all data sources with a GetDataSourcesAsync function.

var dashboards = await client.Dashboards.GetDashboardsInGroupAsync(GroupId);


which match exactly the configuration of that data source in the Power BI service


As you can see; there are also properties for accessing the credentials. or even changing it.

Data Source Management

In addition to reading list of data sources, you can do some other operations such as creating a data source, setting up credentials for it. and even binding a data source to a gateway.

Create Data Source

There is a function to create data source, called CreateDatasourceAsync. You need to specify data source through a new object of PublishDatasourceToGatewayRequest for that. this object can contain type of data set, and connection information about it including credentials.


Binding Data Set to a Gateway

after creating the data source, then you can bind a data set to that gateway. For finding the particular data set, please read the previous blog post. when you have the data set key, then you can easily use BindToGatewayInGroupAsync function;

client.Datasets.BindToGatewayInGroupAsync(GroupId, datasetKey, new BindToGatewayRequest(gateway.Id));


There are many other data source and gateway functions that you can use, make sure you explore the REST API and find out more about all functions. Next post will be about posting data rows to a real-time streaming data set through REST API. Stay tuned.

Reza Rad on FacebookReza Rad on LinkedinReza Rad on TwitterReza Rad on Youtube
Reza Rad
Trainer, Consultant, Mentor
Reza Rad is a Microsoft Regional Director, an Author, Trainer, Speaker and Consultant. He has a BSc in Computer engineering; he has more than 20 years’ experience in data analysis, BI, databases, programming, and development mostly on Microsoft technologies. He is a Microsoft Data Platform MVP for 12 continuous years (from 2011 till now) for his dedication in Microsoft BI. Reza is an active blogger and co-founder of RADACAD. Reza is also co-founder and co-organizer of Difinity conference in New Zealand, Power BI Summit, and Data Insight Summit.
Reza is author of more than 14 books on Microsoft Business Intelligence, most of these books are published under Power BI category. Among these are books such as Power BI DAX Simplified, Pro Power BI Architecture, Power BI from Rookie to Rock Star, Power Query books series, Row-Level Security in Power BI and etc.
He is an International Speaker in Microsoft Ignite, Microsoft Business Applications Summit, Data Insight Summit, PASS Summit, SQL Saturday and SQL user groups. And He is a Microsoft Certified Trainer.
Reza’s passion is to help you find the best data solution, he is Data enthusiast.
His articles on different aspects of technologies, especially on MS BI, can be found on his blog:

Leave a Reply