我可以帮您翻译这句话:如何筛选出在图查询中没有经理的用户?

huangapple go评论76阅读模式
英文:

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&amp;$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 = &quot;https://graph.microsoft.com/v1.0/users?$expand=manager&amp;$select=id,userPrincipalName&quot;
headers = {
    &quot;Authorization&quot;: &quot;Bearer &lt;access_token&gt;&quot;
}

response = requests.get(url, headers=headers)
data = response.json()

users_with_manager = [user for user in data[&quot;value&quot;] if user.get(&quot;manager&quot;)]

for user in users_with_manager:
    print(&quot;User ID:&quot;, user[&quot;id&quot;])
    print(&quot;User Principal Name:&quot;, user[&quot;userPrincipalName&quot;])

Response:

我可以帮您翻译这句话:如何筛选出在图查询中没有经理的用户?

huangapple
  • 本文由 发表于 2023年7月13日 15:16:23
  • 转载请务必保留本文链接:https://go.coder-hub.com/76676817.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定