首页 文章

为Microsoft Graph创建一个等效于“包含”的筛选器查询

提问于
浏览
8

我需要为Microsoft Graph API创建一个 $filter 查询,以查找字符串中的特定单词(用户的显示名称) .

例如,我希望能够找到名称中包含"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”:“找到名为'contains'的未知函数 . 这也可能是导航属性的键查找,这是不允许的 . ”, “innerError”:{“request-id”:“e5ed5c30-4e62-4497-8976-1d38167e759d”,“date”:“2018-09-13T23:17:17”}}}

虽然Microsoft Graph docs说他们支持OData 4.0,但他们也这样说:

“任何Microsoft Graph资源当前都不支持包含字符串运算符 . ”

我还尝试了OData documentationconstruction rules给出的其他命令,它们应该被 filter 和其他查询参数支持 .

特别是我尝试了这些命令的组合:

startswith以indexof subsof结尾

但没有成功 . 似乎MS Graph API不支持除_1496623之外的任何内容 .

我尝试了v1.0和API的beta endpoints .

Is there any other way, some smart combination of OData 4.0 commands and/or query parameters supported by the MS Graph API, that allows a search equivalent to contains?

PS:您可以使用Graph Explorer here尝试查询 .

3 回答

  • -1

    如您所知,Graph API现在不支持您的要求 . 我的建议是首先获取用户列表,然后进行内存过滤 . 这种方式也适用于其他不支持的Graph API .

    同时,在User Voice中投票existing feature request或提交一份新的 .

  • 1

    这似乎是唯一可以为您提供所需列表而无需自己过滤所有用户的替代方案

    https://graph.microsoft.com/v1.0/me/people?$search=Esteban&$top=100000
    

    按照这个blog post,microsoft-graph api只支持 $filter
    等于(eq)
    不等于(ne)
    大于(gt)
    大于或等于(ge)
    小于(lt),小于或等于(le)
    和(和)
    或(或)
    不是这样的)
    以 . . 开始
    任何

    $search 仅支持“messages”和“person”实体 .

  • 3

    我不熟悉这个特定的API,但由于它是一个OData服务,它可能支持该参数

    $filter=substringof('Test',FieldName)
    $filter=substringof('Esteban', displayName)
    

    请注意,与startswith相比,它具有相反的参数顺序 .

    查看OData Docs here了解其他过滤选项

相关问题