Forum Discussion

AbdelmonemKaabi's avatar
AbdelmonemKaabi
Frequent Visitor
6 months ago
Solved

401 Unauthorized when calling Power BI Admin Add User API with Service Principal (Fabric Administrat

  Hello everyone, I’m trying to add a Service Principal as Contributor to all Power BI workspaces using the Admin REST API, but I consistently receive HTTP 401 Unauthorized, even though all require...
  • V-yubandi-msft's avatar
    V-yubandi-msft
    6 months ago

    Hi AbdelmonemKaabi ,

    To clarify, a Service Principal does not need to be a workspace Admin to use: 

    POST /admin/groups/{workspaceId}/users

    This API works with apponly authentication and is designed for tenant level automation scenarios like yours.

     

    Since Admin read APIs are functioning and your script runs successfully locally, the 401 error indicates the identity or token used during the Azure Automation run is not being authorized.

    Please check that the Service Principal used in Automation:

    1. Is the same Client ID assigned the Fabric Administrator role & Is part of the tenant setting security group

    2. Receives a token with Tenant.ReadWrite.All

    3. Uses the Application (Client) ID, not the Object ID, as the identifier

     

    There are no known Fabric side restrictions preventing this method.

     

    Regards,
    Yugandhar