0
votes

I'm trying to retrieve the list of dashboards and reports from PowerBI via its api. In my previous post I have an issue with the connection with the apis. I fixed it.

I'm using the latest packages from Microsoft for PowerBI.

enter image description here

Now, I'm trying to get the list of dashboards or reports in a particular group with this code:

if (await CreatePowerBIClient())
{
    var dashboards = await client.Dashboards.GetDashboardsInGroupAsync(new Guid(SettingsModels.GroupId));
    var reports = await client.Reports.GetReportsInGroupAsync(new Guid(SettingsModels.GroupId));
    
    // doing something else with the list
}

I grab the groupId from the URL

enter image description here

What I get is an error

Microsoft.Rest.HttpOperationException: Operation returned an invalid status code 'NotFound'

enter image description here

Then, I thought it was a configuration error. Then, I tried to get the list from the Microsoft documentation and I received the list of dashboards or reports.

enter image description here

Also, I tried to download the Microsoft example from GitHub but after a quick setup, I got a similar error. The project I ran was DotNetCorePaaS.

enter image description here

In Active Directory, the API permissions are enable for Power BI services.

enter image description here

What is the correct way to get dashboards and reports?

Update

I checked in the Admin portal on PowerBI and those are the values.

enter image description here

Also, I was reading this article on the Microsoft documentation, but I don't have the option "Workspace access". The following picture is from the Microsoft documentation:

enter image description here

and this is mine (I'm not an admin)

enter image description here

Second update

The administrator added the application in the PowerBI to have a service principal. When I try to read the list of groups or workspaces from my web application, I still receive an error.

Then I tried to run DotNetCorePaaS and I ended up in the same situation. Also, I tried to read the list of groups and the result is no groups.

string groupEndPoint = $"https://api.powerbi.com/v1.0/myorg/groups";
HttpResponseMessage groupApiResponse = embedTokenClient.GetAsync(groupEndPoint).Result;
if (groupApiResponse.StatusCode == HttpStatusCode.OK)
{
    string groupContent = groupApiResponse.Content.ReadAsStringAsync().Result;
    JObject groupResponse = JsonConvert.DeserializeObject(groupContent) as JObject;
}

enter image description here

If I run the same query from the Microsoft documentation I have my result.

enter image description here

The URL the app is calling is

https://api.powerbi.com/v1.0/myorg/groups/04639c90-832b-4d25-8852-eb5d14313f8d/reports/ddfb8877-932e-48d0-9f69-f96e5236504b

enter image description here

and if I check this URL with the PowerBI is similar or at least the WorkspaceId and ReportId are the same

https://app.powerbi.com/groups/04639c90-832b-4d25-8852-eb5d14313f8d/reports/ddfb8877-932e-48d0-9f69-f96e5236504b/ReportSection

enter image description here

Then, I tried to have access directly to a report with this code:

var rsp = await client.Reports.GetReportAsync(
                          new Guid("ddfb8877-932e-48d0-9f69-f96e5236504b"));

In this case I receive a Forbidden error.

enter image description here

The last thing I checked was the report link generated by PowerBI. Apart from the parameter cid, groupId and reportId are what I expect.

https://app.powerbi.com/groups/04639c90-832b-4d25-8852-eb5d14313f8d/reports/ddfb8877-932e-48d0-9f69-f96e5236504b?ctid=0306b564-e855-4e8a-ad57-2cf9b2b3c830

PS: I have just noticed at the end of the "Register your application for Power BI" this text:

Note: An application registered here can’t be used as a service principal. Learn how to register a service principal

enter image description here

But in another Microsoft document, I can see this important message:

If you enable service principals to be used with Power BI, the Azure Active Directory permissions don't take effect anymore. The permissions are managed through the Power BI admin portal.

This procedure created a new application in Active Directory. I'm using this application to set up the service principal. Can I do that or I have to create a new app?

Last update with solution

In PowerBI I have created a new workspace. With this one, I can set the Workspace access: here I can find my application from Active Directory! The code is working!

1
Normally an HTTP response status code is 200 OK. Error indicates you are getting an error and probably getting a 400/500 error. There are three possibilities for the error 1) The sample request is using https (secure) where TLS is used for authentication. You could be using the wrong version of TLS 2) The request is bad 3) You are missing a header(s). The best way of debugging is to use a sniffer like wireshark or fiddler. If you are a working app compare the woring and non working. You could use Postman. Check the version of TLS and the headers in the 1st request.jdweng
did you give the app principal permission to the workspace at the power bi service end ?Satya V
I update the post with more details. I followed the Microsoft documentation step 4 but I can't find this option. I'm not adminEnrico
Now, the admin added the app principal permission but I have the same error.Enrico

1 Answers

1
votes

The problem was in the permission of workspaces. I created a new one and now the code is working without any changes.

In the post I added the process I followed to arrive at the solution.