Skip to main content
Showing results for 
Search instead for 
Did you mean: 

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

New Member

Power BI Embed report JavaScript

How to Embed Power BI Reports for my Own Application so that non-bi users can access it. Apart from using by Iframe i want to use Rest API. 

I am Stuck how to generate this token and how to get this.  

I have Referred this Project to testing.


In This, i want to know how can I get from my Power BI Report. I have created some sample Reports and want it to show for my own application for non- BI user 

1. Embed Token

2. Embed URL

3. report id 


I have already registered by application in

made an account in Azure Portal but can't get 


Please Provide Step by Step with images if can be 




You can find all the steps needed to setup the enviroment and start embedding,
in this link-

View solution in original post


How to apply trend line on existing report embed using power bi client api or authoring client api? is there js client methods available to do that? please provide pointers



The process for embedding for non power bi users are all in this demo App Owns Data.

To get the Embedded Token, Embed URL and report id, the first step is to get an accesstoken, see code snippet from this HomeController.cs.



            var credential = new UserPasswordCredential(Username, Password);

            // Authenticate using created credentials
            var authenticationContext = new AuthenticationContext(AuthorityUrl);
            var authenticationResult = await authenticationContext.AcquireTokenAsync(ResourceUrl, ClientId, credential);



And then


// Create a Power BI Client object. It will be used to call Power BI APIs.
            using (var client = new PowerBIClient(new Uri(ApiUrl), tokenCredentials))
                // Get a list of reports.
                var reports = await client.Reports.GetReportsInGroupAsync(GroupId);

                // Get the first report in the group.
                var report = reports.Value.FirstOrDefault();

                if (report == null)
                    return View(new EmbedConfig()
                        ErrorMessage = "Group has no reports."

                // Generate Embed Token.
                var generateTokenRequestParameters = new GenerateTokenRequest(accessLevel: "view");
                var tokenResponse = await client.Reports.GenerateTokenInGroupAsync(GroupId, report.Id, generateTokenRequestParameters);

                if (tokenResponse == null)
                    return View(new EmbedConfig()
                        ErrorMessage = "Failed to generate embed token."

                // Generate Embed Configuration.
                var embedConfig = new EmbedConfig()
                    EmbedToken = tokenResponse,
                    EmbedUrl = report.EmbedUrl,
                    Id = report.Id

Actually, underlying the code calls those POWER BI REST APIs Get Reports and GenerateToken .


@Eric_Zhang I have been folowing these article

Access token for non-Power BI users (app owns data)


and have patterned my web app's Controller.cs to get an Embed Token.. unfortunately, I am stuck with an exception that I am not sure what the root cause is.


What has been so far:


1. An AAD user with Power BI Pro License

2. App workspace with 1 dashboard uploaded - connected to our CUBE hosted in Azure Analysis Services server

3. Registered my web-app into Azure AAD, assigned permissions into both Power BI service and AAD


I am able to login to AAD using the ClientID and ClientSecret:



var clientId = ""; // took out actual value
var clientSecret = ""; // took out actual value
var authContext = new AuthenticationContext("");
var credential = new ClientCredential(clientId, clientSecret);
var authRes = (AuthenticationResult)authContext.AcquireTokenAsync("", credential).Result;

var aadToken = authRes.AccessToken; // all good!

// get Embed Token for app workspace dashboard identified by groupId and dashboardId
var groupId = ""; // took out actual value
var dashboardId = ""; // took out actual value

var tokenCredentials = new TokenCredentials(aadToken , "Bearer");
using (var client = new PowerBIClient(new Uri(""), tokenCredentials))
var generateTokenRequestParameters = new GenerateTokenRequest(accessLevel: "view");

// GenerateTokenInGroup is throwing exception: Operation returned an invalid status code 'Forbidden'
var tokenResponse = client.Dashboards.GenerateTokenInGroup(groupId, dashboardId, generateTokenRequestParameters); // Generate Embed Configuration. var embedConfig = new { EmbedToken = tokenResponse, EmbedUrl = "", Id = dashboardId }; }


First difference I can note of between the sample and my implementation is I am not using the Async version of the method. I am using GenerateTokenInGroup instead of GenerateTokenInGroupAsync. Is it required to use GenerateTokenInGroupAsync ?


I haven't setup anything in Power BI Premium or that one where we need to assign capacity, I don't think that's required in development stage. 


What am I missing?



Thanks a lot. Need to Be Done in Javascript can you Give me the steps or help out how to create azure and all the thinks by step by step 

thanks once again 


You can find all the steps needed to setup the enviroment and start embedding,
in this link-

Would a PowerBI Pro Trial version work?

Office 365 displays my Power BI account as Free.

Helpful resources

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.


Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.


Fabric certifications survey

Certification feedback opportunity for the community.