Forum Discussion
Using Power BI API in C#
- 7 months ago
Hi bigmac025 ,
Thanks for the update and for sharing the decoded token details.
To clarify the point around roles and permissions, the documentation is referring to delegated Power BI permissions when it states that admin-consent required permissions must not be present for service principal authentication. In an app-only setup, the app registration should not have any delegated Power BI permissions configured.
This does not conflict with assigning a Power BI Admin or Fabric Admin tenant role to the service principal. Tenant roles are evaluated by the Power BI service at runtime and are separate from Azure AD delegated permissions. Admin REST APIs such as GetGroupsAsAdminAsync() are authorized based on tenant-level configuration, not on delegated scopes in the token.
So to address both points together, including AmosHersch 's comment, the presence of Tenant.Read.All or Tenant.ReadWrite.All in an app-only token does not cause the 401 and does not need to be removed. Those scopes are relevant only for delegated admin user tokens and are ignored when using service principal authentication.
Since the token itself is valid, a 401 from GetGroupsAsAdminAsync() still points to tenant-level authorization. Please recheck that service principal access is enabled in the Power BI Admin portal and that the service principal or its security group is allowed, that the service principal has a Power BI Admin or Fabric Admin tenant role, and that no delegated Power BI permissions are configured on the app registration.
Once these are in place, the updated code using GetGroupsAsAdminAsync() and GetReportsAsAdminAsync() should work as expected.
Hope this helps. Please reach out for further assistance.
Thank you.
Hi bigmac025 ,
Thanks for reaching out to Microsoft Fabric Community and for sharing the document reference.
When using GetGroupsAsAdminAsync() with service principal authentication, Power BI validates tenant level settings and admin role assignment rather than delegated scopes. In the Power BI Admin portal, ensure that Allow service principals to use Power BI APIs is enabled under Tenant settings, and that your service principal or the security group containing it is added to the allowed list. The service principal must also have Fabric Admin role assigned. If any of these are missing, the API returns 401 even with a valid token.
This behavior is documented here:
Embed Power BI content in an embedded analytics application with service principal and an application secret - Power BI | Microsoft Learn
Admin - Groups GetGroupsAsAdmin - REST API (Power BI Power BI REST APIs) | Microsoft Learn
Enable service principal authentication for admin APIs - Microsoft Fabric | Microsoft Learn
There are also similar community threads where the same issue was resolved by updating tenant settings or admin role assignment:
Solved: Re: Power Bi REST API - 401 Authorization error wh... - Microsoft Fabric Community
Solved: Re: Unauthorized 401 when accessing Power BI Admin... - Microsoft Fabric Community
Once the service principal is enabled in the tenant settings and has the required admin role, the existing API calls should work as expected.
Hope this helps. Please reach out for further assistance.
Thank you.