Power BI is turning 10, and we’re marking the occasion with a special community challenge. Use your creativity to tell a story, uncover trends, or highlight something unexpected.
Get startedJoin us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.
Hi all. I try to pass and use UserId (string) in token request parameter instead of the username. It's look like this:
var generateTokenRequestParameters = new GenerateTokenRequest("View", null,
identities: new List<EffectiveIdentity> {
new EffectiveIdentity(
username: userId, roles: new List<string> {"role"}, datasets: new List<string> {datasets}
)});
And then I try to get token response by this parameters:
tokenResponse = await client.Reports.GenerateTokenInGroupAsync(groupId, reportId, generateTokenRequestParameters);
But I immediately get an error: "Microsoft.Rest.HttpOperationException: Operation returned an invalid status code 'BadRequest'"
Table filter DAX expression look like this: [UserId] = USERNAME(). (UserId - string field)
What am I doing wrong and how can this problem be solved?
Solved! Go to Solution.
Hi @stas317,
Could you try using the code below to see if it works?
// This is how you create embed token with effective identities if (!string.IsNullOrEmpty(username))//replace usename with your userId { var rls = new EffectiveIdentity(username, new List<string> { report.DatasetId }); if (!string.IsNullOrWhiteSpace(roles)) { var rolesList = new List<string>(); rolesList.AddRange(roles.Split(',')); rls.Roles = rolesList; } // Generate Embed Token with effective identities. generateTokenRequestParameters = new GenerateTokenRequest(accessLevel: "view", identities: new List<EffectiveIdentity> { rls }); } else { // Generate Embed Token for reports without effective identities. generateTokenRequestParameters = new GenerateTokenRequest(accessLevel: "view"); } var tokenResponse = await client.Reports.GenerateTokenInGroupAsync(GroupId, report.Id, generateTokenRequestParameters);
Regards
Hi @stas317,
Could you try using the code below to see if it works?
// This is how you create embed token with effective identities if (!string.IsNullOrEmpty(username))//replace usename with your userId { var rls = new EffectiveIdentity(username, new List<string> { report.DatasetId }); if (!string.IsNullOrWhiteSpace(roles)) { var rolesList = new List<string>(); rolesList.AddRange(roles.Split(',')); rls.Roles = rolesList; } // Generate Embed Token with effective identities. generateTokenRequestParameters = new GenerateTokenRequest(accessLevel: "view", identities: new List<EffectiveIdentity> { rls }); } else { // Generate Embed Token for reports without effective identities. generateTokenRequestParameters = new GenerateTokenRequest(accessLevel: "view"); } var tokenResponse = await client.Reports.GenerateTokenInGroupAsync(GroupId, report.Id, generateTokenRequestParameters);
Regards
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
8 | |
7 | |
2 | |
2 | |
2 |
User | Count |
---|---|
6 | |
5 | |
4 | |
4 | |
4 |