英文:
How can I sort through the Graph query users who do not have a Manager?
问题
我尝试获取在我的组织中拥有manager的用户。
但我获取了所有用户,包括有经理和没有经理的用户。
在响应中,我只需要拥有manager的用户。
如何筛选它们?
英文:
I tried to get users who have manager in my organization.
https://graph.microsoft.com/v1.0/users?$expand=manager&$select=id,userPrincipalName
But I get all users, those with managers and those without managers.
In the response I need only users who have manager.
How can I filter them ?
答案1
得分: 0
当我运行与您相同的查询时,我也得到了与具有经理和没有经理的用户相同的结果,如下所示:
GET https://graph.microsoft.com/v1.0/users?$expand=manager&$select=id,userPrincipalName
响应:
请注意,没有直接的图查询可以检索仅具有经理的用户。相反,您可以使用任何编程语言来自定义上述查询的响应。
在我的情况下,我使用以下Python代码,仅在响应中获取具有经理的用户,如下所示:
import requests
url = "https://graph.microsoft.com/v1.0/users?$expand=manager&$select=id,userPrincipalName"
headers = {
"Authorization": "Bearer <access_token>"
}
response = requests.get(url, headers=headers)
data = response.json()
users_with_manager = [user for user in data["value"] if user.get("manager")]
for user in users_with_manager:
print("用户ID:", user["id"])
print("用户主体名称:", user["userPrincipalName"])
响应:
英文:
When I ran the same query as you, I too got same results with users having manager and without manager like below:
GET https://graph.microsoft.com/v1.0/users?$expand=manager&$select=id,userPrincipalName
Response:
> Note that, there is no direct graph query to retrieve only users
> having manager. Instead, you can use any coding language to
> customize the response of above query.
In my case, I used below Python code and got only users having manager in the response like below:
import requests
url = "https://graph.microsoft.com/v1.0/users?$expand=manager&$select=id,userPrincipalName"
headers = {
"Authorization": "Bearer <access_token>"
}
response = requests.get(url, headers=headers)
data = response.json()
users_with_manager = [user for user in data["value"] if user.get("manager")]
for user in users_with_manager:
print("User ID:", user["id"])
print("User Principal Name:", user["userPrincipalName"])
Response:
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论