无法在 Microsoft Graph Api 中按收件人筛选邮件。一个或多个无效节点

Unable to filter messages by recipient in Microsoft Graph Api. One or more invalid nodes

我正在尝试从 Microsoft Graph API 中获取按收件人筛选的邮件列表。我用于请求的 url 是:

https://graph.microsoft.com/beta/me/messages?$filter=toRecipients/any(r: r/emailAddress/address eq '[Email Address]')

但我得到的是这样的回应:

{
   "error": {
        "code": "ErrorInvalidUrlQueryFilter",
        "message": "The query filter contains one or more invalid nodes.",
        "innerError": {
            "request-id": "7db712c3-e337-49d9-aa8d-4a5d350d8480",
            "date": "2016-09-28T16:58:34"
        }
    }
}

一个成功的请求应该是这样的(还有很多我省略的数据)。

{
    "@odata.context": "https://graph.microsoft.com/beta/$metadata#users('99999999-9999-9999-9999-999999999999')/messages",
    "@odata.nextLink": "https://graph.microsoft.com/beta/me/messages?$skip=10",
    "value": [
        {
            "toRecipients": [
                {
                    "emailAddress": {
                        "name": "[Name]",
                        "address": "[Email Address]"
                    }
                }
            ],
        }
    ]
}

如果我删除过滤器,该请求将有效,并且我能够使用更简单的过滤器执行请求。

是我的 URL 有问题,还是有其他方法可以提出请求?

发出请求的另一种方法可能是不使用过滤器而是使用搜索,具体取决于您想要什么(您可能已经尝试过):

https://graph.microsoft.com/beta/me/messages?$search="to:[Email Address]"

经过几个小时的寻找解决方案,我在office365文档中发现属性 toRecipients是不可过滤的:

https://msdn.microsoft.com/en-us/office/office365/api/complex-types-for-mail-contacts-calendar#MessageResource

我猜在图中也是一样的api。所以唯一的解决办法是使用搜索。