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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
MichaelWash
Helper I
Helper I

Paginated Report embedding using a Power BI Dataset - How to pass the xmlaPermissions parameter?

Microsoft announced: 

Support Power BI dataset as a data source for embedding paginated reports

 

It indicates:

When embedding a paginated report with a Power BI dataset as a datasource for the embed for your customers scenario, you need a service principal and a multi-resource embed token, that contains a new parameter called “XMLA permissions”. Using this parameter, ISVs and customers can control the access to XMLA endpoints with the embed token. For allowing embedding of paginated report with a Power BI dataset as a datasource a “Read Only” value is required.

 

That leads to this example, that requires a xmlaPermissions parameter. Can anyone provide any example code that does that?

 

1 ACCEPTED SOLUTION

This code works:

 

 

public EmbedToken GetEmbedToken(PowerBIClient pbiClient, Guid reportId, Guid datasetId, Guid targetWorkspaceId)
{
        EmbedToken embedToken = new EmbedToken();

        try
        {
            // Create a request for getting Embed token 
            // This method works only with new Power BI V2 workspace experience
            var tokenRequest = new GenerateTokenRequestV2(

reports: new List<GenerateTokenRequestV2Report>() 
{ new GenerateTokenRequestV2Report(reportId) },
datasets: new List<GenerateTokenRequestV2Dataset>() 
{ new GenerateTokenRequestV2Dataset(datasetId.ToString(), "ReadOnly") },
targetWorkspaces: targetWorkspaceId != Guid.Empty ? new List<GenerateTokenRequestV2TargetWorkspace>() { 
   new GenerateTokenRequestV2TargetWorkspace(targetWorkspaceId) } : null,

   identities: new List<EffectiveIdentity> {
   // This first EffectiveIdentity is needed only if 
   // the Dataset uses Row Level Security
      new EffectiveIdentity(
          username: "user@user.com",
          roles: new List<string> { "A Role" },
          datasets: new List<string> { datasetId.ToString() }
       ), 
       new EffectiveIdentity(
       username: "user@user.com" ,
       reports: new List<string> { reportId.ToString() } 
       ) 
      }
     );

            // Generate Embed token
            embedToken = pbiClient.EmbedToken.GenerateToken(tokenRequest);
        }
        catch (Exception ex)
        {
            string errorMessage = ex.GetBaseException().Message;
        }

        return embedToken;
    }

 

View solution in original post

2 REPLIES 2
chan_kevin
New Member

I have tried to get the EmbedToken by referring to this example:

 

PowerBI-Developer-Samples/PbiEmbedService.cs at master · microsoft/PowerBI-Developer-Samples · GitHu...

 

I created the PowerBIclient object in main function without problem, then pass into this function:

 

public void GetEmbedToken(PowerBIClient pbiClient, Guid reportId, Guid datasetId, Guid targetWorkspaceId)
{
try
{
// Create a request for getting Embed token
// This method works only with new Power BI V2 workspace experience
var tokenRequest = new GenerateTokenRequestV2(

reports: new List<GenerateTokenRequestV2Report>() { new GenerateTokenRequestV2Report(reportId) },

datasets: new List<GenerateTokenRequestV2Dataset>() { new GenerateTokenRequestV2Dataset(datasetId.ToString()) },

targetWorkspaces: targetWorkspaceId != Guid.Empty ? new List<GenerateTokenRequestV2TargetWorkspace>() { new GenerateTokenRequestV2TargetWorkspace(targetWorkspaceId) } : null


);

// Generate Embed token
var embedToken = pbiClient.EmbedToken.GenerateToken(tokenRequest);


}
catch (Exception ex)
{
string errorMessage = ex.GetBaseException().Message;
}

//return embedToken;
}

 

 

However, error returned when generate the token:  Operation returned an invalid status code 'BadRequest'

 

Does any one has any idea?

 

 

This code works:

 

 

public EmbedToken GetEmbedToken(PowerBIClient pbiClient, Guid reportId, Guid datasetId, Guid targetWorkspaceId)
{
        EmbedToken embedToken = new EmbedToken();

        try
        {
            // Create a request for getting Embed token 
            // This method works only with new Power BI V2 workspace experience
            var tokenRequest = new GenerateTokenRequestV2(

reports: new List<GenerateTokenRequestV2Report>() 
{ new GenerateTokenRequestV2Report(reportId) },
datasets: new List<GenerateTokenRequestV2Dataset>() 
{ new GenerateTokenRequestV2Dataset(datasetId.ToString(), "ReadOnly") },
targetWorkspaces: targetWorkspaceId != Guid.Empty ? new List<GenerateTokenRequestV2TargetWorkspace>() { 
   new GenerateTokenRequestV2TargetWorkspace(targetWorkspaceId) } : null,

   identities: new List<EffectiveIdentity> {
   // This first EffectiveIdentity is needed only if 
   // the Dataset uses Row Level Security
      new EffectiveIdentity(
          username: "user@user.com",
          roles: new List<string> { "A Role" },
          datasets: new List<string> { datasetId.ToString() }
       ), 
       new EffectiveIdentity(
       username: "user@user.com" ,
       reports: new List<string> { reportId.ToString() } 
       ) 
      }
     );

            // Generate Embed token
            embedToken = pbiClient.EmbedToken.GenerateToken(tokenRequest);
        }
        catch (Exception ex)
        {
            string errorMessage = ex.GetBaseException().Message;
        }

        return embedToken;
    }

 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.