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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Ven
Frequent Visitor

REST with Reports Fine with Groups 403 Forbidden Error

Hi

 

I've been trying to folow the examples provided in GitHub https://github.com/Microsoft/PowerBI-CSharp I'm using the sample code for the 'integrate-report-web-app' and it works great I can see the reports from my Workspace fine. However I want the see the list of groups so I change the URL from

 

https://api.powerbi.com/v1.0/myorg/Reports

 

To

 

https://api.powerbi.com/v1.0/myorg/Groups

 

I can get the groups fine from the 'Power BI API' site no problem but when I try with the C# with the adjusted URL I log in fine then get the following

 

{StatusCode: 403, ReasonPhrase: 'Forbidden', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:
{
  Strict-Transport-Security: max-age=31536000; includeSubDomains
  X-Frame-Options: deny
  X-Content-Type-Options: nosniff
  RequestId: 02152c64-6429-46f2-a717-24af736856b8
  Date: Wed, 05 Oct 2016 10:17:39 GMT
  Server: Microsoft-HTTPAPI/2.0
  Content-Length: 0
}} System.Net.Http.HttpResponseMessage

 

Any ideas why this would be giving me this result considering it was happy to get the reports?

 

 

1 ACCEPTED SOLUTION
Ven
Frequent Visitor

So I've managed to figure this out and the answer is "Permissions"

 

When originally following the tutorial for the 'Integrate Report Web App' that when you register teh application in the Azure AD to get your 'Client ID' and 'Client Secret' to tick some boxes

 

Azure Permission 1.png

 

So notice that the "Read All Groups" box isn't ticked.

 

So I've gone back and registered the app this time with all boxes ticked

 

Azure Permission 2.png

 

After updating the 'Client ID' and 'Client Secret' in my code I can now read the list of groups with the endpoint:

 

https://api.powerbi.com/v1.0/myorg/Groups

 

 

 

 

 

 

View solution in original post

3 REPLIES 3
Eric_Zhang
Employee
Employee


I've been trying to folow the examples provided in GitHub https://github.com/Microsoft/PowerBI-CSharp I'm using the sample code for the 'integrate-report-web-app' and it works great I can see the reports from my Workspace fine. However I want the see the list of groups so I change the URL from

 

https://api.powerbi.com/v1.0/myorg/Reports

 

To

 

https://api.powerbi.com/v1.0/myorg/Groups

 

I can get the groups fine from the 'Power BI API' site no problem but when I try with the C# with the adjusted URL I log in fine then get the following

Any ideas why this would be giving me this result considering it was happy to get the reports? 


@Ven

The sample is a demo of embedding a report, what did you do after changing the url? If you'd like to get the reports in a specific group, the url would be something like

https://api.powerbi.com/v1.0/myorg/Groups/{groupid}/Reports

Hi Eric_Zhang

 

Thanks for the reply.

 

Yes I can get get the reports from a group with the Group ID as per your example endpoint

 

https://api.powerbi.com/v1.0/myorg/Groups/{groupid}/Reports

 

However the Power BI API says I should be able to get a list of groups with the following

 

https://api.powerbi.com/v1.0/myorg/Groups

 

I've tried the example code provided by the "Power BI API" site

 

using System;
using System.Net.Http;

var baseAddress = new Uri("https://api.powerbi.com/");

using (var httpClient = new HttpClient{ BaseAddress = baseAddress })
{

  httpClient.DefaultRequestHeaders.TryAddWithoutValidation("authorization", "Bearer tokenString");
  
  using(var response = await httpClient.GetAsync("v1.0/myorg/groups"))
  {
 
        string responseData = await response.Content.ReadAsStringAsync();
  }

 

 

However I get an error for the authentication about needing to supply the client secret which I'm currently trying to work out how to provide in a console app.

 

It seems that installing the NuGet Package using the following as per the instructions on Power BI Developer site at the bottom

 

Install-Package Microsoft.IdentityModel.Clients.ActiveDirectory

 

Then gives an compile issue that the AuthenticationContext class doesn't contain a method called AcquireToken. This means that the code from the Power BI Developer Site needs updating to show how to include the 'Client Secret'.

 

I can't seem to find a working code example to authenticate with the latest packages and get a list of the Groups.

 

Thats the difficulties of my morning Eric hows yours going?

 

Ven
Frequent Visitor

So I've managed to figure this out and the answer is "Permissions"

 

When originally following the tutorial for the 'Integrate Report Web App' that when you register teh application in the Azure AD to get your 'Client ID' and 'Client Secret' to tick some boxes

 

Azure Permission 1.png

 

So notice that the "Read All Groups" box isn't ticked.

 

So I've gone back and registered the app this time with all boxes ticked

 

Azure Permission 2.png

 

After updating the 'Client ID' and 'Client Secret' in my code I can now read the list of groups with the endpoint:

 

https://api.powerbi.com/v1.0/myorg/Groups

 

 

 

 

 

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.