C# Wrapper for Power BI REST API

Since the last major update last year, Power BI offers some APIs which can be used to interact with content and also data that is stored in Power BI. Microsoft provides a good set of samples on how to use the APIs on GitHub and also a an interactive APIARY web-UI which you can use to build and test API calls on-the-fly. However, it can still be quite cumbersome as you have to deal with all the REST API calls and the returned JSON on your own. So I decided to write a little C# Wrapper where you simply pass in your Azure AD Application Client ID and you can deal with all Object of the Power BI API as they were regular C# objects.

Here is a little example on how to list all available reports and get the EmbedURL of a given tile using the PowerBIClient:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using pmOne.PowerBI;
using pmOne.PowerBI.PowerBIObjects;

namespace SampleApplication
    class Program
        static void Main(string[] args)
            PowerBIClient pbic = new PowerBIClient(“ef4aed1a-9cab-4bb3-94ea-ffffffffffff”);

            Console.WriteLine(“Available Reports:”);
            foreach(PBIReport pbir in pbic.Reports)

            Console.WriteLine(“Get EmbedURL for Tile [Retail Analysis Sample].[This Year’s Sales]”);
            Console.WriteLine(pbic.GetDashboardByName(“Retail Analysis Sample”).GetTileByName(“This Year’s Sales”).EmbedURL);

            Console.WriteLine(“Press <Enter> to exit …”);

As you can see, its pretty simple and very easy to use, even for non-developers. You can find all the source-code and the sample application for download below. The code as I have written it is very likely not the best code possible, but it works for my needs, is straight forward, simple and saves me a lot of work and time when dealing with the PowerBI API. Also, if the API changes, you may need to adopt the code accordingly. However, for the future I hope that Microsoft provides some metadata so that VisualStudio can build all this code automatically using e.g. Swagger. But for the time being feel free to use, improve or extend my code Smile

SourceCode: PowerBIClient_Source.zip

7 thoughts on “C# Wrapper for Power BI REST API

    • yes, I have seen it. it looks very good and is probably a much better code than mine. But to be fully honest, its too advanced for me (and I guess also to must other users) and I like to understand the code that I am using in my projects:)

      and as I said, I still hope for MS to publish the API metadata so we can use VS to generate all this code for us automatically …

  1. I’m investigating the generation of a data feed to Azure Power BI, along with the Azure Power BI parameters that are required to generate a graph in Azure Power BI.

    A series of questions will be presented to the user using a set of rules that determine the next question(s) to be presented — these questions will determine which data (held in Azure SQL) is to be used by Azure Power BI to generate a graph.

    The parameters of the graph will be included as part of the feed to Azure Power BI, or the feed will select a pre-saved template in Azure Power BI for the graph to be generated.

    I would be interested to view any cases where something like this has been achieved.

Leave a Reply