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
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
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.