You can interact with the Power BI objects in the Power BI Service through a set of APIs called Power BI REST API. The Power BI REST API can help automate tasks, build tools that work with Power BI, the configuration of Power BI outside of the platform, and embed Power BI into a third-party application. In this article and video, I’ll explain REST API, why it is useful, and a few examples.
Video
Power BI REST API
A REST API is a type of web service that can be used with or without some parameters and provide responses on a specific area. In the case of Power BI, Power BI REST API is a set of web services that can work with the Power BI objects in the Power BI service. There are many use cases for REST API for Power BI. Below are some examples;
- Refreshing the dataset automatically if it failed
- Refresh the dataset immediately after successfully finishing the refresh of all related dataflows
- Creating a deployment pipeline
- Embedding Power BI report or dashboard into a web application
- Automating documentation of Power BI service objects
- Sending data rows to a streaming dataset in the Power BI service
- Extracting the usage of Power BI objects by the users
- and many other scenarios.
Power BI REST APIs can be used in programming (.NET or other languages), PowerShell, and other tools. Most of the use case for the APIs is through a programming language. This article won’t go into the details of the program in which we invoke the REST API. Instead, we focus on where to get the information and the possibilities.
Getting Started
To start working with REST API for Power BI, you can go to this link; https://learn.microsoft.com/en-us/rest/api/power-bi/. This is the link to the documentation for the REST API. The REST API operation is categorized into groups to find the function you are looking for easily.
The list above gets updated regularly, and you can expect more functions and operations available through the REST API in the future.
Once you click on an operation group, you will see all functions under that group.
The list above is for the REST API functions for the Power BI Reports. If you compare this list with the Power BI Cmdlets for PowerShell for the reports, you can see how extensive the REST API list is. This shows you immediately that the REST API is more powerful than the PowerShell Cmdlets for Power BI (although the PowerShell Cmdlets are easier to use for non-programmers).
A helpful thing in the Microsoft documentation for these REST APIs is that you have the option to TRY a REST API function from the web browser page, this way you can call the function within your environment using your Power BI account and see if this is what you are looking for or not.
For example, if you run the Get Refresh History API for a sample dataset, you can get the response through the TRY window in the browser.
Some APIs require the Id of the objects in the Power BI service. These Ids are the unique identifier codes that can be fetched through the URL of the object in the Power BI service or even through the response of some other API functions.
Calling the API from .NET
As mentioned before, most REST API usage is from a custom application or program. C# or VB.NET are the two most commonly used languages in Microsoft world for using the REST API of Power BI. To use the REST API through these programming languages, you can download (or install) the .NET SDK for Power BI (which gets updated regularly).
This Power BI NuGet will give the programmer the list of functions to use;
An example of such an application is the Power BI Helper, which uses the functions in the .NET SDK of Power BI to get some Power BI service documentation.
To get started with the .NET SDK of Power BI, an application must be registered for Power BI in your organization’s tenant active directory. Then there is an authentication process to complete. If you are interested to learn more about it and learn some samples of working with the .NET SDK of Power BI, read the article series below;
- Integrate Power BI into a custom application; Part 1 – Register the application.
- Integrate Power BI into a custom application; Part 2 – Authentication
- Integrate Power BI into a custom application; Part 3 – Embedded
- Integrate Power BI into a custom application; Part 4 – Refresh the dataset
- Integrate Power BI into a custom application; Part 5 – Manage the data source
- Integrate Power BI into a custom application; Part 6 – Send data rows to real-time streaming dataset
Embedding into a custom application
A common use case for the REST API of Power BI is embedding the report or dashboard into a custom web application. Power BI documentation has two good resources for that;
The first link is all the documentation you need for the Power BI Embedded. The Power BI Playground is an interesting place to run some embedded code as a test in the browser and see how it works.
The playground environment gives you a sandbox to see how code results perform in the application, get the sample codes, and even run it for your tenant.
Power Automate
Some of the most common REST API functions for Power BI are streamlined through Power Automate. Power Automate is a service for designing flow and automation. You can, for example, use the Power BI functions in automate to do tasks like the below;
Power Automate includes a user-friendly UI; you don’t need to be a programmer to work with the Power BI functions there. An example of using Power Automate functions for Power BI is using Power Automate to trigger as soon as an entry to a Microsoft Form is submitted and send the result to a real-time streaming Power BI dataset.
PowerShell to call REST API
Another approach to call the REST API is through a PowerShell command called Invoke_RestMethod. Here is the documentation of this function with some samples of how to use it.
Summary
Power BI REST APIs are web services that can work with the Power BI service objects (such as workspaces, datasets, dataflows, reports, etc.). Using the REST API, a programmer can use a custom application to automate some configurations for a Power BI service solution and extend the solution to another level. Things that are not possible through the normal GUI of the Power BI service might be possible options through the REST API.