Retrieve user details from Microsoft 365 admin center

Eugenie Meng 146 Reputation points
2021-08-31T09:39:09.653+00:00

Hi,

I have a question on how to retrieve the user details from M365 admin center. I understand there is this "Export users" function from the portal. But I need to establish an automated data feed from Microsoft365 admin center into SQL server DB for reporting purpose. We are mainly interested in understanding which user has what licenses.
127837-image.png

I was wondering if Graph API is the right type of API to retrieve such user details. I tested https://graph.microsoft.com/v1.0/users but it doesn't give License info from the users (e.g. Unlicensed vs Power BI etcs)

Apart from API option, is there a report subscription function from this M365 portal? So that the user details can be sent as a csv file to my email on a weekly/monthly basis.

Thanks for any suggestions.

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,651 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Danstan Onyango 3,741 Reputation points Microsoft Employee
    2021-09-01T07:53:58.78+00:00

    In your case you should try List Users https://graph.microsoft.com/v1.0/users?$select=assignedLicenses,id which will return assigned license details.

    To get it to work with email delivery, you can have an app that has access to subscribedsku and make it aware of them. Then you make your app call GET https://graph.microsoft.com/v1.0/users?$select=assignedLicenses,id which returns something like:

    {  
        "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users(assignedLicenses,id)",  
        "value": [  
            {  
                "@odata.id": "https://graph.microsoft.com/v2/...",  
                "id": "a74...",  
                "assignedLicenses": []  
            },  
            {  
                "@odata.id": "https://graph.microsoft.com/v2/...",  
                "id": "a20..",  
                "assignedLicenses": [  
                    {  
                        "disabledPlans": [],  
                        "skuId": "c42b9cae-ea4f-4ab7-9717-81576235ccac"  
                    }  
                ]  
            }  
        ]  
    }  
    

    With the subscribedsku and user assignedLicenses, you can have the report. You can also checkout PowerAutomate as this can work well if you call Graph from there but I am not sure because I am still new to PowerAutomate.