Skip to content

Unable to access admin API using service principal authentication #799

@ishan1510

Description

@ishan1510

What are you trying to achieve?
I am working with semantic-link-labs library to get audit log and some other info like list of reports, workspaces, users, capacities etc. Its working when I'm signed in using the power BI admin account but want to get it work using the service principal.

What have you tried so far?
Based on the guidelines and documentation given by MS I have given all necessary permission and role but its not working. I'm unable to find what else is missing.

Here's what I have done -

  • Created a service principal.
    Assigned it fabric administrator role.
    Added following API permissions -
    Microsoft Graph - Directory.Read.All, User.Read.All (application)
    Power BI service - Tenant.ReadWrite.All (Application) & Delegated permission on Capacity, Item, Lakehouse, OneLake, Report, Semantic Model, Tenant, Warehouse etc.
  • Create a security group and added this service principal into it as a member.
  • Power BI Admin portal -
    Developer Settings
    Enable all service principal related options and added the security group into it.
    Admin API settings
    Enabled "Service principal can access read-only admin API's" & "Service principal can access admin API's used for updates.

Code
import sempy_labs as labs
from sempy_labs import admin, graph
from sempy_labs.tom import connect_semantic_model

with labs.service_principal_authentication(
key_vault_uri = 'https://ishankeyvault01.vault.azure.net/',
key_vault_tenant_id = 'TenantID',
key_vault_client_id = 'ClientID',
key_vault_client_secret = 'ClientSecret'):

df1 = admin.list_capacities()
display(df1)

Error Message
FabricHTTPException: 401 Unauthorized for url: https://api.fabric.microsoft.com//v1.0/myorg/admin/capacities
Error: {"error":{"code":"PowerBINotAuthorizedException","pbi.error":{"code":"PowerBINotAuthorizedException","parameters":{},"details":[],"exceptionCulprit":1}}}
Headers: {'Cache-Control': 'no-store, must-revalidate, no-cache', 'Pragma': 'no-cache', 'Transfer-Encoding': 'chunked', 'Content-Type': 'application/json; charset=utf-8', 'Strict-Transport-Security': 'max-age=31536000; includeSubDomains', 'X-Frame-Options': 'deny', 'X-Content-Type-Options': 'nosniff', 'RequestId': 'ab4476dc-6858-4c80-bc3c-bb78d9787d5c', 'Access-Control-Expose-Headers': 'RequestId', 'request-redirected': 'true', 'home-cluster-uri': 'https://wabi-india-central-a-primary-redirect.analysis.windows.net/', 'Date': 'Fri, 08 Aug 2025 06:37:39 GMT'}

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions