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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
janfcarl
Helper I
Helper I

Problem with PowerBIClient (GetReportsInGroupAsync)

EDIT:

I was able to fix the problem by adding

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

to the method GetTokenCredentials.

 

My next problem is that the call

var requestParameters = new GenerateTokenRequest();

var tokenResponse = await client.Reports.GenerateTokenInGroupAsync(workspaceID, id, requestParameters);

throws an other error: 

Operation returned an invalid status code 'Forbidden'

We are hoping to clarify on this with Microsoft directly.

 

We are having problems with connecting to Power BI Service from within an .Net web application. The c# code being used is

 

var tokenCredentials = await GetTokenCredentials(authorityUrl, clientID, resourceUrl);

//resourceUrl = https://analysis.windows.net/powerbi/api

...

var apiUri = new Uri(apiUrl);  //apiUrl = https://api.powerbi.com/

using (var client = new PowerBIClient(apiUri, tokenCredentials))
{
var reportList = await client.Reports.GetReportsInGroupAsync(workspaceID);
...
}

 

The last line of code throws an error:

An existing connection was forcibly closed by the remote host

Can anyone tell or guess what the problem is? The user we use to receive token credentials is a Power BI pro user.

 

private static async Task<TokenCredentials> GetTokenCredentials(string authorityUrl, string clientID, string resourceUrl)
{
var credential = new UserPasswordCredential(azureADUserName, azureADPassword);
var context = new AuthenticationContext(authorityUrl, TokenCache.DefaultShared);
var result = await context.AcquireTokenAsync(resourceUrl, clientID, credential);

if (result == null)
return null;

return new TokenCredentials(result.AccessToken, "Bearer");
}

3 REPLIES 3
Anonymous
Not applicable

Hi  @janfcarl  ,

 I'm glad to hear that you solved this problem. If you want to get support directly from Microsfot, you can get the information here:

 

This is the website of the support ticket:

https://powerbi.microsoft.com/en-us/support/

 

How to create a support ticket in Power BI:

https://community.powerbi.com/t5/Community-Blog/How-to-create-a-support-ticket-in-Power-BI/ba-p/6830...

 

Best Regards,

Liu Yang

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

Thank you, I was able to fix the problem, but have a new problem now (updated the post). Perhaps you can take a look, but we are looking for support from Microsoft directly.

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

Fabric Community Sticker Design Challenge Barcelona Carousel

Fabric Community Sticker Challenge - Barcelona 2026

If you love stickers, then you will definitely want to check out our community sticker challenge, Barcelona edition!

July Power BI Update Carousel

Power BI Monthly Update - July 2026

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

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.

Top Kudoed Authors