我需要创建一个 $filter
查询用于在字符串(用户的显示名称)中搜索特定单词的 Microsoft Graph API。
例如,我希望能够找到名称中包含“Esteban”的所有用户:
Luis Esteban
Alphonse Esteban
Esteban Luis
Alphonse Esteban Luis
以下查询有效,但只返回名称中以“Esteban”开头的用户,而不返回包含“Esteban”的用户:
https://graph.microsoft.com/v1.0/users?$filter=startswith(displayName,'Esteban')
我也尝试使用
contains
而不是 startswith
,但它给出了错误响应:{ "error": { "code": "Request_BadRequest", "message": "An unknown function with name 'contains' was found. This may also be a key lookup on a navigation property, which is not allowed.", "innerError": { "request-id": "e5ed5c30-4e62-4497-8976-1d38167e759d", "date": "2018-09-13T23:17:17" } } }
即使 Microsoft Graph docs说他们支持 OData 4.0,他们还说:
"The contains string operator is currently not supported on any Microsoft Graph resources."
我还尝试了 OData documentation 给出的其他命令和 construction rules应该由
filter
支持的和其他查询参数。特别是我尝试了这些命令的组合:
startswith
endswith
indexof
substring
但没有成功。似乎 MS Graph API 不支持除
startswith
之外的任何内容。无论如何。我尝试了 v1.0 和 API 的 beta 端点。
有没有其他方法,MS Graph API 支持的 OData 4.0 命令和/或查询参数的一些智能组合,允许搜索等效于
contains
? PS:您可以使用 Graph Explorer here 尝试查询.
最佳答案
如您所知,Graph API 现在不支持您的要求。我的建议是先获取用户列表,然后进行内存过滤。这种方式也适用于其他不支持的 Graph API。
同时,请务必投票支持 existing feature request在 User Voice或提交一个新的。
关于search - 为 Microsoft Graph 创建一个等效于 "contains"的筛选器查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52321911/