KanisXXX
KanisXXX

Reputation: 777

How to get unlicensed users in Microsoft GraphAPI

Is there any GraphApi to get a list of all unlicensed or licensed users in O365, I have found This link which having this report api

GET https://graph.microsoft.com/v1.0/reports/getOffice365ActivationsUserDetail

which is returning Activated users in CSV format. But I need data in List.

Upvotes: 0

Views: 2387

Answers (1)

KanisXXX
KanisXXX

Reputation: 777

So after trying many things, I found a simple way to check user license status for every user. You have to call user_get API with additional property parameter assignedLicenses using OData $select query. Since By default, only a limited set of properties are returned ( businessPhones, displayName, givenName, id, jobTitle, mail, mobilePhone, officeLocation, preferredLanguage, surname, userPrincipalName ).

So for getting all user with license info you must issue GET request adding $select=assignedLicenses.

Example:

GET https://graph.microsoft.com/v1.0/users?$select=displayName,givenName,userPrincipalName,assignedLicenses,surname

And response will be user with given parameters such as

 {
        "displayName": "displayName-value",
        "givenName": "given-name",
        "surname": "surname",
        "userPrincipalName": "[email protected]",
        "assignedLicenses": [
            {
                "disabledPlans": [],
                "skuId": "skuId-value"
            }
        ]
    }

After getting all user records you can check whether any user have license assigned or not.

Upvotes: 3

Related Questions