Yes it is expected if you are calling the global endpoint instead of your reginal one, because preferClientRouting=true bypasses the redirect step.
If you want to fix it without manually adding the parameter, you can:
1. Point PowerBiClient directly to your reginal base URL(no redirect needed).
2. Or customize the HttpClientHandler used by PowerBIClient to preserve the authorization header and follow 307 redirects.
Static async Task Main()
{ //Your azure AD token for Power BI
String accessToken =”<YOUR_ACCESS_TOKEN>”;
//The global API endpoint
String baseUrl = “https://api.powerbi.com/”;
//Create HTTP handler that preserves authorization header on redirects
Var handler= new AuthRedirectHandler(new HttpClientHandler(), accessToken);
Var httpClient = new HttpClient(handler);
//Create PowerBIClient using your token and custom HTTP handler
Var tokenCredentials = new TokenCredentials(accessToken, “Bearer”);
Var powerBIClient = new PowerBIClient(new Uri(baseUrl), tokenCredentials, httpClient);
//Example API call: get all workspaces(groups)
Var groups = await powerBIClient.Groups.GetGroupAsync();
Foreach(var group in group.Value)
{
Console.WriteLine($”Group: {group.Name}”);
}
}
What it does:
· Gets your token(accessToken)- needed for authentication with Power BI Rest API
· Wraps HttpClientHandler inside a custom AuthRedirectHandler to follow 307 redirects and keep the bearer token.
· Creates PowerBIClient with the global API URL, Your token credentials and the customer HttpClient for redirect handling.
· Calls GetGroupAsync() to list all PowerBI workspaces your account can access.
· Loops through and prints their names.
Hope this helps. Please try and let me know if any other query