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

Did you hear? There's a new SQL AI Developer certification (DP-800). Start preparing now and be one of the first to get certified. Register now

Reply
Anonymous
Not applicable

Operation returned an invalid status code 'BadRequest'

I tried to use RLS with PowerBi embedded analytics. I followed steps from 

Using row-level security with embedded content in Power BI embedded analytics - Power BI | Microsoft...

 

This is my code to generate tokens:

 

public EmbedToken GetEmbedToken(Guid reportId, IList<Guid> datasetIds, [Optional] Guid targetWorkspaceId)

PowerBIClient pbiClient = this.GetPowerBIClient();

// 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: datasetIds.Select(datasetId => new GenerateTokenRequestV2Dataset(datasetId.ToString())).ToList(),

targetWorkspaces: targetWorkspaceId != Guid.Empty ? new List<GenerateTokenRequestV2TargetWorkspace>() { new GenerateTokenRequestV2TargetWorkspace(targetWorkspaceId) } : null,
identities: new List<EffectiveIdentity> { { new EffectiveIdentity(username: "*****", roles: new List<string> { "***" }, datasets: new List<string> { datasetIds.ToString() }) } }); ;

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

return embedToken;
}

But I get the following error

 

PBIuser2010_0-1660105343401.png

 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Anonymous ,

 

Please check whether the parameters like report id/dataset id in your code are correct.

I think you can try to post a Rest API to generate a Embed token for the report with RLS.

For refernece:  Embed Token - Generate Token - REST API (Power BI Power BI REST APIs) | Microsoft Docs

Here is a solved post with similar issue like yours, I think you may refer to it to learn more details.

Solved: Re: Power BI send “invalid status code 'Bad Reques... - Microsoft Power BI Community

 

Best Regards,
Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

1 REPLY 1
Anonymous
Not applicable

Hi @Anonymous ,

 

Please check whether the parameters like report id/dataset id in your code are correct.

I think you can try to post a Rest API to generate a Embed token for the report with RLS.

For refernece:  Embed Token - Generate Token - REST API (Power BI Power BI REST APIs) | Microsoft Docs

Here is a solved post with similar issue like yours, I think you may refer to it to learn more details.

Solved: Re: Power BI send “invalid status code 'Bad Reques... - Microsoft Power BI Community

 

Best Regards,
Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

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

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.