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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Coder86
Regular Visitor

PowerBiClient executequeries giving 'BadRequest' response.

Hi @Anonymous ,

I am calling powerBI rest APIs using C# with authentication. I can able to get datasets and groups using PowerBIClient class. While executing ExecuteQueryInGroup method gives me bad request error. 

Below is the sample code to generate token and getting datasets and groups using PowerBIClient API class.

 

AuthenticationResult? authenticationResult = null;
IEnumerable<string> scopes = new string[] { "https://analysis.windows.net/powerbi/api/.default" };
var tenantSpecificUrl = "https://login.microsoftonline.com/tenent_Id/oauth2/token";

PublicClientApplication clientApp = PublicClientApplicationBuilder.Create("appId").
WithAuthority(tenantSpecificUrl).WithClientId("clientId").Build();
var userAccounts = clientApp.GetAccountsAsync().Result;
try
{
if (userAccounts == null)
{
authenticationResult = clientApp.AcquireTokenSilent(scopes, userAccounts?.FirstOrDefault()).ExecuteAsync().Result;
}
else
{
authenticationResult = clientApp.AcquireTokenByUsernamePassword(scopes, "username", "password").ExecuteAsync().Result;
}
}
catch (MsalUiRequiredException)
{

}
return authenticationResult.AccessToken;

 

Get Dataset and Use Below Code to ExecuteQueries

DatasetExecuteQueriesResponse datasetExecuteQueriesResponse =
client.Datasets.ExecuteQueriesInGroup(new Guid("xxxxx"),
"xxxxx", datasetDatasetExecuteQueriesRequest);

 

The above code give me error "Operation returned an invalid status code 'BadRequest'"

 

Can someone help what am I missing here?

1 REPLY 1
Anonymous
Not applicable

Hi @Coder86 ,

Can you please share some more detail information about this issue? They should help us clarify your scenario and test to troubleshoot.

How to Get Your Question Answered Quickly  

Regards,

Xiaoxin Sheng

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.