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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
avendanof
Helper I
Helper I

Bad request when embeeding an analisys services based report

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: 

 
 
And in this seccion of the code
 

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

 
And this
 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
It seems that I send all the parameters needed, and with otrer kind of reports I have no errors. I tried with direct query also.
The report in the Power Bi services work fine, so, is not a matter of the gateway or the connecion.
I have to deliver this to a clinet and I´m really worried about this.
 
Thanks for any help.
 
Felix
2 ACCEPTED SOLUTIONS
avendanof
Helper I
Helper I

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

View solution in original post

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;
}

View solution in original post

2 REPLIES 2
avendanof
Helper I
Helper I

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;
}

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.