The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
I´m trying to embeed a report based on a multidimensional cube in analisys services and I´m getting a bad request message.
I´m testing it with the AppsOwnData application that is in here:
var tokenRequest = new GenerateTokenRequestV2(
reports: new List<GenerateTokenRequestV2Report>() { new GenerateTokenRequestV2Report(reportId) },
datasets: datasetIds.Select(datasetId => new GenerateTokenRequestV2Dataset(datasetId.ToString())).ToList(),
targetWorkspaces: targetWorkspaceId != Guid.Empty ? new List<GenerateTokenRequestV2TargetWorkspace>() { new GenerateTokenRequestV2TargetWorkspace(targetWorkspaceId) } : null
);
I´m getting this error
Operation returned an invalid status code 'BadRequest'
at Microsoft.PowerBI.Api.EmbedTokenOperations.GenerateTokenWithHttpMessagesAsync(GenerateTokenRequestV2 requestParameters, Dictionary`2 customHeaders, CancellationToken cancellationToken)
at Microsoft.PowerBI.Api.EmbedTokenOperationsExtensions.GenerateTokenAsync(IEmbedTokenOperations operations, GenerateTokenRequestV2 requestParameters, CancellationToken cancellationToken)
at Microsoft.PowerBI.Api.EmbedTokenOperationsExtensions.GenerateToken(IEmbedTokenOperations operations, GenerateTokenRequestV2 requestParameters)
at AppOwnsData.Services.PbiEmbedService.GetEmbedToken(Guid reportId, IList`1 datasetIds, Guid targetWorkspaceId) in C:\Proyectos\Snipets\PBIEmbeedSampleCode\AppOwnsData\Services\PbiEmbedService.cs:line 167
at AppOwnsData.Services.PbiEmbedService.GetEmbedParams(Guid workspaceId, Guid reportId, Guid additionalDatasetId) in C:\Proyectos\Snipets\PBIEmbeedSampleCode\AppOwnsData\Services\PbiEmbedService.cs:line 75
at AppOwnsData.Controllers.EmbedInfoController.GetEmbedInfo() in C:\Proyectos\Snipets\PBIEmbeedSampleCode\AppOwnsData\Controllers\EmbedInfoController.cs:line 46
Status: BadRequest (400) Response: {"error":{"code":"InvalidRequest","message":"Creating embed token for accessing dataset 970249ad-922d-49b3-8b22-d1235440c37c requires effective identity to be provided"}} RequestId: f2391c10-c1af-4a31-ae15-7a8b0c62d927
Solved! Go to Solution.
I´ve already came to the solution.
This is the idea:
public EmbedToken GetEmbedToken(Guid reportId, IList<Guid> datasetIds, [Optional] Guid targetWorkspaceId)
{
PowerBIClient pbiClient = this.GetPowerBIClient();
// Define the user identity and roles. Use one of the following:
var rlsidentity = new EffectiveIdentity( // If no RLS
username: "User", // can also be username@contoso.com
datasets: new List<string> { datasetIds.First().ToString() }
);
// Create a request for getting an embed token for the rls identity defined above
// This method works only with new Power BI V2 workspace experience
var tokenRequest = new GenerateTokenRequestV2(
reports: new List<GenerateTokenRequestV2Report>() { new GenerateTokenRequestV2Report(reportId) },
datasets: datasetIds.Select(datasetId => new GenerateTokenRequestV2Dataset(datasetId.ToString())).ToList(),
targetWorkspaces: targetWorkspaceId != Guid.Empty ? new List<GenerateTokenRequestV2TargetWorkspace>() { new GenerateTokenRequestV2TargetWorkspace(targetWorkspaceId) } : null
,identities: new List<EffectiveIdentity> { rlsidentity}
);
tokenRequest.Datasets.First().Validate(EffectiveIdentity);
// Generate an embed token
var embedToken = pbiClient.EmbedToken.GenerateToken(tokenRequest);
return embedToken;
}
The problem I've got now is how to detect if the dataset needs effective identity
Inthe end, this is the solution
public EmbedToken GetEmbedToken(Guid reportId, IList<Guid> datasetIds, [Optional] Guid targetWorkspaceId)
{
PowerBIClient pbiClient = this.GetPowerBIClient();
EmbedToken embedToken = new EmbedToken();
// Define the user identity and roles. Use one of the following:
//Los reportes no utilizan roles
var rlsidentity = new EffectiveIdentity( // If no RLS
username: "username@contoso.com",
datasets: new List<string> { datasetIds.First().ToString() }
); ;
// Create a request for getting an embed token for the rls identity defined above
// This method works only with new Power BI V2 workspace experience
//controlo que se necesite EffectiveIdentity. Para los reportes paginados o los modelos tabulares no hace falta
var dataset = pbiClient.Datasets.GetDatasetInGroup(targetWorkspaceId, datasetIds.First().ToString());
if( dataset.IsEffectiveIdentityRequired == true) {
var tokenRequest = new GenerateTokenRequestV2(
reports: new List<GenerateTokenRequestV2Report>() { new GenerateTokenRequestV2Report(reportId) },
datasets: datasetIds.Select(datasetId => new GenerateTokenRequestV2Dataset(datasetId.ToString())).ToList(),
targetWorkspaces: targetWorkspaceId != Guid.Empty ? new List<GenerateTokenRequestV2TargetWorkspace>() { new GenerateTokenRequestV2TargetWorkspace(targetWorkspaceId) } : null
,identities: new List<EffectiveIdentity> { rlsidentity} //aquí es donde controlo
);
embedToken = pbiClient.EmbedToken.GenerateToken(tokenRequest);
}
else {
var tokenRequest = new GenerateTokenRequestV2(
reports: new List<GenerateTokenRequestV2Report>() { new GenerateTokenRequestV2Report(reportId) },
datasets: datasetIds.Select(datasetId => new GenerateTokenRequestV2Dataset(datasetId.ToString())).ToList(),
targetWorkspaces: targetWorkspaceId != Guid.Empty ? new List<GenerateTokenRequestV2TargetWorkspace>() { new GenerateTokenRequestV2TargetWorkspace(targetWorkspaceId) } : null
);
embedToken = pbiClient.EmbedToken.GenerateToken(tokenRequest);
}
// Generate an embed token
return embedToken;
}
I´ve already came to the solution.
This is the idea:
public EmbedToken GetEmbedToken(Guid reportId, IList<Guid> datasetIds, [Optional] Guid targetWorkspaceId)
{
PowerBIClient pbiClient = this.GetPowerBIClient();
// Define the user identity and roles. Use one of the following:
var rlsidentity = new EffectiveIdentity( // If no RLS
username: "User", // can also be username@contoso.com
datasets: new List<string> { datasetIds.First().ToString() }
);
// Create a request for getting an embed token for the rls identity defined above
// This method works only with new Power BI V2 workspace experience
var tokenRequest = new GenerateTokenRequestV2(
reports: new List<GenerateTokenRequestV2Report>() { new GenerateTokenRequestV2Report(reportId) },
datasets: datasetIds.Select(datasetId => new GenerateTokenRequestV2Dataset(datasetId.ToString())).ToList(),
targetWorkspaces: targetWorkspaceId != Guid.Empty ? new List<GenerateTokenRequestV2TargetWorkspace>() { new GenerateTokenRequestV2TargetWorkspace(targetWorkspaceId) } : null
,identities: new List<EffectiveIdentity> { rlsidentity}
);
tokenRequest.Datasets.First().Validate(EffectiveIdentity);
// Generate an embed token
var embedToken = pbiClient.EmbedToken.GenerateToken(tokenRequest);
return embedToken;
}
The problem I've got now is how to detect if the dataset needs effective identity
Inthe end, this is the solution
public EmbedToken GetEmbedToken(Guid reportId, IList<Guid> datasetIds, [Optional] Guid targetWorkspaceId)
{
PowerBIClient pbiClient = this.GetPowerBIClient();
EmbedToken embedToken = new EmbedToken();
// Define the user identity and roles. Use one of the following:
//Los reportes no utilizan roles
var rlsidentity = new EffectiveIdentity( // If no RLS
username: "username@contoso.com",
datasets: new List<string> { datasetIds.First().ToString() }
); ;
// Create a request for getting an embed token for the rls identity defined above
// This method works only with new Power BI V2 workspace experience
//controlo que se necesite EffectiveIdentity. Para los reportes paginados o los modelos tabulares no hace falta
var dataset = pbiClient.Datasets.GetDatasetInGroup(targetWorkspaceId, datasetIds.First().ToString());
if( dataset.IsEffectiveIdentityRequired == true) {
var tokenRequest = new GenerateTokenRequestV2(
reports: new List<GenerateTokenRequestV2Report>() { new GenerateTokenRequestV2Report(reportId) },
datasets: datasetIds.Select(datasetId => new GenerateTokenRequestV2Dataset(datasetId.ToString())).ToList(),
targetWorkspaces: targetWorkspaceId != Guid.Empty ? new List<GenerateTokenRequestV2TargetWorkspace>() { new GenerateTokenRequestV2TargetWorkspace(targetWorkspaceId) } : null
,identities: new List<EffectiveIdentity> { rlsidentity} //aquí es donde controlo
);
embedToken = pbiClient.EmbedToken.GenerateToken(tokenRequest);
}
else {
var tokenRequest = new GenerateTokenRequestV2(
reports: new List<GenerateTokenRequestV2Report>() { new GenerateTokenRequestV2Report(reportId) },
datasets: datasetIds.Select(datasetId => new GenerateTokenRequestV2Dataset(datasetId.ToString())).ToList(),
targetWorkspaces: targetWorkspaceId != Guid.Empty ? new List<GenerateTokenRequestV2TargetWorkspace>() { new GenerateTokenRequestV2TargetWorkspace(targetWorkspaceId) } : null
);
embedToken = pbiClient.EmbedToken.GenerateToken(tokenRequest);
}
// Generate an embed token
return embedToken;
}
User | Count |
---|---|
5 | |
5 | |
2 | |
2 | |
2 |
User | Count |
---|---|
10 | |
7 | |
4 | |
4 | |
4 |