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.
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
What I get is an error
Microsoft.Rest.HttpOperationException: Operation returned an invalid status code 'NotFound'
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.
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.
In Active Directory, the API permissions are enable for Power BI services.
What is the correct way to get dashboards and reports?
Update
I checked in the Admin portal on PowerBI and those are the values.
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:
and this is mine (I'm not an admin)
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;
}
If I run the same query from the Microsoft documentation I have my result.
The URL the app is calling is
and if I check this URL with the PowerBI is similar or at least the WorkspaceId
and ReportId
are the same
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.
The last thing I checked was the report link generated by PowerBI. Apart from the parameter cid
, groupId and reportId are what I expect.
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
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!