繁体   English   中英

使用 Microsoft Graph SDK 获取具有特定电子邮件域的所有用户

[英]Get all users with a specific email domain using Microsoft Graph SDKs

我想使用 Microsoft Graph SDK 对 Microsoft Graph API 进行此查询。 我想让电子邮件地址中域的所有用户都是@something.com。

使用带有endsWith 运算符的$filter

GET ../users?$count=true&$filter=endsWith(mail,'@something.com')

我尝试了以下代码行:

var users= await _graphServiceClient.Users.Request().Filter("mail '@something.com'").Select(u => new {
                u.Mail,
                u.DisplayName,
            }).GetAsync();

我得到的错误是:

    Microsoft.Graph.ServiceException: 'Code: BadRequest
Message: Invalid filter clause

没有过滤器,它工作正常。 我错过了什么吗?

参考:高级查询: https : //docs.microsoft.com/en-us/graph/query-parameters Microsoft Graph SDKs: https : //docs.microsoft.com/en-us/graph/sdks/create-requests?标签= CS

如果您想使用$count查询参数,您需要添加具有eventual值的ConsistencyLevel标头。

GET /users?$count=true&$filter=endsWith(mail,'@something.com')
ConsistencyLevel: eventual

在 C# 中为请求指定标头选项和查询选项:

var options = new List<Option>();
options.Add(new HeaderOption("ConsistencyLevel", "eventual"));
options.Add(new QueryOption("$count", "true"));

向过滤器添加endsWith运算符。

var users = await _graphServiceClient.Users
    .Request(options)
    .Filter("endsWith(mail,'@something.com')")
    .GetAsync();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM