PowerBI Embedded Full Walk Through

This walk through cre­ates a sim­ple PowerBI MVC app that can embed reports.  It uses the App-Owns data model pop­u­lar for use by ISV's.

Make sure the account you're using is a Power BI Pro account.  You'll need a Pro account to do embed­ding.

Register an Azure AD app

First, we need to get the app we're going to build reg­is­tered with Active Direc­tory.  Login to PowerBI and go here:


Make sure to select Native app. Even though we're embed­ding to a web page we still need to select Native app. 'Server-side Web app' is for some­thing else.

Write down your Client ID.  This is the same as what Azure calls the Appli­ca­tion ID.

Apply Azure AD permissions

Your app will access the REST APIs via a mas­ter account.  In order to do this the mas­ter account must be given per­mis­sion.  This is done by log­ging in to the Azure por­tal using the mas­ter account and going to Active Direc­tory / App reg­is­tra­tions.  Make sure to select 'All apps' so you can see your embed­ded app.


We need to enable "Access the direc­tory as the signed-in user".

And finally, Grant those Per­mis­sions.  The mas­ter account you're logged in as now has those rights.

Power BI rights should auto­mat­i­cally be con­fig­ured when the app was reg­is­tered.  If not, click Power BI Ser­vice, select the nec­es­sary Per­mis­sions, Save, and Grant Per­mis­sion for those as well.

Create Web Project

Visual C# / ASP.NET Web Appli­ca­tion (.NET Frame­work)

Create PowerBI App Workspace

This is where your PowerBI .pbix files will be uploaded to.


Get your Group ID GUID

Click on your new App Work­space to open it.

And copy the GUID from the Url.  This is your Group Id (App Work­spaces used to be called groups).

Publish a PBIX to your new App Workspace

I've always got a sim­ple of sim­ple PBIX lying around for test­ing.  Mine's called Colors.pbix. Feel free to down­load and rename (don't extract, just rename) to Colors.pbix.

Open your PBIX, make sure your logged in under the mas­ter account, then Pub­lish your file to your new App Work­space.


Setup Web.config

Use the Client ID you saved off dur­ing App Reg­is­tra­tion above to set "pbi.clientId"

Use the Group ID we got from cre­at­ing our new App Work­space above to set "pbi.groupId"

Then use the mas­ter account's cre­den­tials for "pbi.user" and "pbi.pass" (obvi­ously encrypt your pass­word or use some­thing like Key­Vault).

Start Coding

I won't be orga­niz­ing my code as one should in a real project but for Demo pur­poses it will do and make things easy peezy.

Setup your Project

Add a class to the Con­troller folder called EmbedManager.cs

Using NuGet install the fol­low­ing pack­ages:

 *        Microsoft.IdentityModel.Clients.ActiveDirectory
 *        Microsoft.PowerBI.Api

Add some using state­ments & pull in your App Set­tings.

Get an Access Token

The first thing you need is an access token so you can make calls into the PowerBI REST API.

Since all Embed­ded func­tion­al­ity works through App Work­spaces, all your REST API  calls using the Power­BIClient wrap­per need to use the InGroup ver­sion.

Let's make our first call into the API to get a list of reports from the App Work­space we cre­ated.

(see below if you have any issues com­pil­ing at this point)

Add a call to GetRe­ports() from the Con­troller:


If you haven't given your app the proper AD per­mis­sions you'll see this:

See "Apply Azure AD per­mis­sions" above to give the cor­rect per­mis­sions.

If all goes well, look at your Out­put win­dow and you should see:

That's it!  The hard parts done.  Now all you have to do is embed the report!

Let's do it…

Cre­ate a tiny class to hold just what you need for embed­ding.

We'll also want to get an Embed Token.  Tech­ni­cally you can use your Access Token to embed the report, but don't!  That's a secu­rity risk because any­one with that token could view other reports that token has access to.  Instead, we want a report speci­fic token that will expire.

Update our Home­Con­troller

Add use our Embed­Con­fig in the View to show the report.

OK, so that's not the rec­om­mended way to do the Javascript part of the embed­ding.  But that's what's going on under the hood and doesn't require any other JavaScript libraries.  Check out this great arti­cle for tons more details.

To do it right, use the PowerBI Javascript library and do it like this.

That's it!  Happy embed­ding.

Possible Issues

Issue: Could not load file or assem­bly 'Newtonsoft.Json, Version=
Solu­tion: Man­age NuGet pack­ages for Solu­tion, Install 7.0.1

Sample Project

Here's a great sam­ple project that includes all the code nec­es­sary to cre­ate App-Owns and User-Owns projects.