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

13 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.

  2. Hi Gerhard, I am very new to this. Your post is really helpful.

    I have a quick question: How can we automate data push into Power BI Service?

    • Hi Rishabh,
      sure, you can can also automate the Pushing of data into the PowerBI Service
      There are a lot of tutorials out there – here are just some links:

      what exactly do you need to automate?

      Also, there have been some recent changes to the API so you need to ensure that the wrapper is still working:

      hope that helps,

      • Just to give you a background, we have hit an issue with Power BI on Dynamics CRM Online. We are getting data from Dynamics CRM Online using Fetch XML . However, we are able to fetch only 5000 records using FetchXML due to its limitation. I read somewhere that we can use Use FetchXML with a paging cookie to fetch the complete dataset. This includes writing C# code.

        So, I was wondering if we can write c# code to get complete data from Dynamics CRM using FetchXML with paging cookie and get the data to be refreshed on a scheduled basis.

        • I’d say that you can achieve the same also with PowerQuery – have you tried this yet?
          I would not use the Push API unless you really need real-time data and your scenario seems to be more like a workaround

          • We are currently trying to extracts data from CRM online using fetchxml.
            To overcome limit of 5000 records we are trying to make smaller extracts of data based on date ranges.
            For example we have monthly extracts for all cases and we are passing that condition(based on dates) as part of fetchxml.
            The data runs well in power BI desktop . However, it faces refresh issue in Power BI online.

            We are thinking to have a workaround. Please do let us know if there are any pointers to alternative

          • As I said in my previous comment, I would rather try to write a PowerQuery/M Script to load the data which executes smaller batches and then combines the data in Power BI

Leave a Reply