Microsoft Graph: List all users and their groups in one request

两盒软妹~` 提交于 2020-01-11 01:29:29

问题


I would like to list all users. For each user, I need to display the roles and groups specific to that user.

I tried:

https://graph.microsoft.com/v1.0/users?$expand=memberOf

But it gives exactly the same result as:

https://graph.microsoft.com/v1.0/users

According to the doc for the user object (http://graph.microsoft.io/en-us/docs/api-reference/v1.0/resources/user), I should be able to list the roles and groups for the user by using the memberOf relationship.

I can get the roles and groups I need for every user by doing one request per user (using https://graph.microsoft.com/v1.0/users/{user_id}/getMemberObjects) but it's a bit slow and overkill.

What am I missing?


回答1:


Expanding navigation properties on user entities is currently not working on the production (v1.0) version of the Microsoft Graph endpoint. The functionality is live on the beta endpoint.

This query works as you desire:

https://graph.microsoft.com/beta/users?$expand=memberOf

There is no timeline on when features move from beta to v1.0 or whether they even will in the current form.

Currently, you have 3 choices using the Microsoft Graph APIs.

Beta endpoint

Use the beta endpoint but understand that it may change in functionality.

Multiple Graph Calls

Fetch the users collection then fetch the memberOf for each user as you need it.

https://graph.microsoft.com/v1.0/users/{id}/memberOf

or

https://graph.microsoft.com/v1.0/users/{user_id}/getMemberObjects

Expand members on Groups

If you want to stick with the v1.0 endpoint and depending on your overall goal, you can attempt to go about finding the information you want the other way. Get the collection of groups and expand the members navigation property instead.

https://graph.microsoft.com/v1.0/groups/?$expand=members


来源:https://stackoverflow.com/questions/39004373/microsoft-graph-list-all-users-and-their-groups-in-one-request

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!