Search code examples
azurepowerbipowerbi-desktopmicrosoft365azure-app-registration

How to connect Power BI to Microsoft 365 admin center


I was reading this amazing piece of documentation:

https://learn.microsoft.com/en-us/office/office-365-management-api/get-started-with-office-365-management-apis

My goal is to try to access the Microsoft 365 admin center and pull the list of our users, each one with their licenses:

enter image description here

The URL I have to point to is this: https://admin.microsoft.com/Adminportal/Home#/users

But when I try to connect with Power BI I receive the error A web API key can only be specified when a web API key name is provided

enter image description here

But I'm providing the key that I've created in the documentation.

What am I doing wrong?

Is there another way to access the list of our Licenses?


Solution

  • Initially, register one Microsoft Entra application and add Reports.Read.All permission of Application type by granting consent like this:

    enter image description here

    You can generate access token using client credentials flow with below parameters via Postman:

    POST https://login.microsoftonline.com/tenantId/oauth2/v2.0/token
    
    grant_type:client_credentials
    client_id: appId
    client_secret: secret
    scope: https://graph.microsoft.com/.default
    

    Response:

    enter image description here

    Now, you can use this access token to call Microsoft Graph API for fetching users along with their licenses:

    GET https://graph.microsoft.com/v1.0/reports/getOffice365ActiveUserDetail(period='D7')
    Authorization: Bearer <token>
    

    Response:

    enter image description here

    In Power BI Desktop, you can create web connection by selecting Advanced and included Authorization header with Bearer token like this:

    enter image description here

    This pulled data with list of users along with their assigned licenses as below:

    enter image description here

    Reference:

    Solved: Licenses and Users List from M365 connecting to P... - Microsoft Fabric Community by v-shex-msft