How to get assignedLicenses from Microsoft Graph

Robin 66 Reputation points
2024-04-19T18:47:55.8666667+00:00

Hi,

I am using a C# program to retrieve user information from Microsoft Graph. Currently I am passing the following URL to get the information I need.

https://graph.microsoft.com/v1.0/users?$filter=accountEnabled eq true&$select=displayName,id

I want to extract only users who have any valid license i.e. exclude users who don't have a license. I don't know how to filter using assignedLicenses on this URL. Can someone please help?

Thanks.

Microsoft Security | Microsoft Graph
Developer technologies | C#
0 comments No comments
{count} votes

Accepted answer
  1. Vasil Michev 119.7K Reputation points MVP Volunteer Moderator
    2024-04-20T17:43:28.33+00:00

    You can use the following query to list only licensed users:

    https://graph.microsoft.com/v1.0/users?$filter=assignedLicenses/$count
    

    Do note that this is an "advanced" query, thus it requires the consistencyLevel=eventual header:

    https://learn.microsoft.com/en-us/graph/aad-advanced-queries?tabs=http

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Sourabh Gupta 800 Reputation points Microsoft External Staff
    2024-04-20T15:07:23.56+00:00

    Hi Robin,

    Thanks for reaching out.

    There is no such direct way in Graph Api to get only those users which have anyone of the licenses assigned.

    However, there are few work arounds which I can suggest you.

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.