簡體   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