Skip to main content
cancel
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.

Reply
Anonymous
Not applicable

How to Generate Token for Report with Shared Dataset?

The code snippet below works fine for a Generic Report which means with Internal Dataset, however If I try to GenerateToken for a Report with an External Dataset meaning a Dataset that lives in another Workspace it throws a 403 Forbidden.

 

Note: I'm using SPN to authenticate my request and SPN is an Admin of Both Workspace (Workspace where the External Dataset Lives and Workspace where the Report lives)

 

using (var pbiClient = await this.GetClientAsync().ConfigureAwait(false))
{
  

if (pbiClient != null)
{
var dataset = await pbiClient.Datasets.GetDatasetByIdInGroupAsync(groupId, datasetId).ConfigureAwait(false);

GenerateTokenRequest genereateTokenRequestParameters;

var identity = new EffectiveIdentity(user.Username.Trim(), new List<string> { dataset.Id })
{
Roles = new List<string> { securityRole }
};

 

genereateTokenRequestParameters = new GenerateTokenRequest(accessLevel: "view", identity: identity);

 

// THIS LINE OF CODE RETURNS 403 FOR REPORT WITH EXTERNAL DATASET,

// WHILE WORKS IF REPORT AND DATASET IS IN THE SAME WORKSPACE
var tokenResponse = await pbiClient.Reports.GenerateTokenInGroupAsync(reportGroupId, report.Id, genereateTokenRequestParameters).ConfigureAwait(false);

 

embedReport.EmbedToken = tokenResponse ?? throw new NullReferenceException($"Power BI token not generated. Report ID: {report.Id}");

 

embedReport.EmbedUrl = report.EmbedUrl;
embedReport.ReportId = report.Id;

return embedReport;
}

 

}

 

 

0 REPLIES 0

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.