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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
JAnder
Helper I
Helper I

Embedded paginated report with PowerBI dataset

In Feb the option of using a Power BI dataset was introduced for embedded paginated reports. 

https://powerbi.microsoft.com/en-us/blog/power-bi-february-2022-feature-summary/#post-18588-_Toc9541...

 

I understand the requirement is slightly different in that you need to now pass the datasetId as well as xmlaPermissions as described here

https://docs.microsoft.com/en-gb/rest/api/power-bi/embed-token/generate-token

 

I have 2 questions based on this, firstly is there a way to extract the datasetId from a report? If I open the RDL file in a text editor I can see it in there, can this be obtained programatically to then use in a request for the token?

 

The second part is, if possible, is there a code example of this being used? The github examples (linked below) do not seem to show this scenario yet. I intend to use the PowerBIClient from the Microsoft.PowerBi.APi nuget.

 

https://github.com/microsoft/PowerBI-Developer-Samples/blob/master/.NET%20Framework/Embed%20for%20yo...

2 ACCEPTED SOLUTIONS
AmosHersch
Employee
Employee

Hi @JAnder ,

The way I am using for obtaining the dataset ID programatically is by calling "Reports - Get Datasources" API https://docs.microsoft.com/en-gb/rest/api/power-bi/reports/get-datasources-in-group the datasource representing the Power BI Dataset will have in the ConnectionDetails.Database something like 

sobe_wowvirtualserver-<DatasetID> .
 
Regarding code sample, I don't think there's a code sample for this specific case, but any sample for embedding RDL report should work, besides the change in generateToken request which should look similar to this: 
 
 

View solution in original post

I posed a code sample here that shows how to get the embed token using the Microsoft.PowerBi.APi nugetSolved: Re: Paginated Report embedding using a Power BI Da... - Microsoft Power BI Community

View solution in original post

12 REPLIES 12
MichaelWash
Helper I
Helper I

@JAnder - For var identities I must pass a new EffectiveIdentity even if I was not using Row Level Secuity like this:

 

var 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() }
)
}

 

I found that looking at the request on Fiddler gives more info that the exception shows. It actually didn't want my effective identity at all. I took out the identity and got the token.

 

{
    "error": {
        "code": "InvalidRequest",
        "message": "Creating embed token for accessing dataset <removed> shouldn't have effective identity"
    }
}

 

 

Can you show me your code?

So it ends up looking like this and is working for now showing the reports. I should say I dont create the report or do the Power BI admin stuff, so there may be settings which now cause me to leave out the identity.

 

I did try using dynamic binding with this but it seems the token request always needs the datasetId used when creating the report. If I supply both (original and one I want to use) it seems to work but I only tested that against a dataset copy, needs more work to know if it is binding to correct dataset.

 var reports = new List<GenerateTokenRequestV2Report>() { new GenerateTokenRequestV2Report(report.Id) };
 var datasets = new List<GenerateTokenRequestV2Dataset>() { new GenerateTokenRequestV2Dataset(datasetId, XmlaPermissions.ReadOnly) };
 var workspaces = new List<GenerateTokenRequestV2TargetWorkspace>() { new GenerateTokenRequestV2TargetWorkspace(groupId) };
                
 var tokenRequest = new GenerateTokenRequestV2(datasets, reports, workspaces, null);
 var embedToken = client.EmbedToken.GenerateToken(tokenRequest);

 return embedToken;

 

Are you using a Service Principal (or Master User and a Password)? If so, perhaps that could explain the difference? See: Accessing dataset  requires effective identity use... - Microsoft Power BI Community

It is Service Principal.

I re-checked our code and yes, if a dataset is not using Row Level Security, it does not need an Effective Identity passed. However, we are *not* getting the error, you are getting, when we do pass an Effective Identity.

I wonder if that could be down to configuration? I've not had much dealing with that. Odd you didn't get the 400 response. Since our code is pretty much the same otherwise, config seems most likely.

AmosHersch
Employee
Employee

Hi @JAnder ,

The way I am using for obtaining the dataset ID programatically is by calling "Reports - Get Datasources" API https://docs.microsoft.com/en-gb/rest/api/power-bi/reports/get-datasources-in-group the datasource representing the Power BI Dataset will have in the ConnectionDetails.Database something like 

sobe_wowvirtualserver-<DatasetID> .
 
Regarding code sample, I don't think there's a code sample for this specific case, but any sample for embedding RDL report should work, besides the change in generateToken request which should look similar to this: 
 
 

Thanks @AmosHersch for the info. Much appreciated.

I posed a code sample here that shows how to get the embed token using the Microsoft.PowerBi.APi nugetSolved: Re: Paginated Report embedding using a Power BI Da... - Microsoft Power BI Community

I am getting bad request on this, I can't spot any deviation from the working example.

The effective identity contains the reportId, datasetId and username. 

 

Any ideas? 

@AmosHersch 

                var reports = new List<GenerateTokenRequestV2Report>() { new GenerateTokenRequestV2Report(report.Id) };
                var datasets = new List<GenerateTokenRequestV2Dataset>() { new GenerateTokenRequestV2Dataset(datasetId, XmlaPermissions.ReadOnly) };
                var workspaces = new List<GenerateTokenRequestV2TargetWorkspace>() { new GenerateTokenRequestV2TargetWorkspace(groupId) };
                var identities = new List<EffectiveIdentity>() { effectiveIdentity };

                var tokenRequest = new GenerateTokenRequestV2(datasets, reports, workspaces, identities);
                var embedToken = client.EmbedToken.GenerateToken(tokenRequest);

                return embedToken;

 

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.