Odata $过滤Office 365 REST API中的日期

时间:2014-08-29 18:41:53

标签: ms-office odata exchangewebservices office365

我尝试使用REST API从其Office 365帐户检索用户的事件,但是按字段" Start"进行过滤。例如,检索日期之后将发生的所有事件:2014-08-29T09:13:28'但我总是检索此错误消息

{
  "error": {
    "code": "ErrorInvalidUrlQuery",
    "message": "The query parameter '$filter' is invalid.",
    "innererror": {
      "message": "The query parameter '$filter' is invalid.",
      "type": "Microsoft.Exchange.Services.OData.InvalidUrlQueryException",
      "stacktrace": " at Microsoft.Exchange.Services.OData.Web.ODataQueryOptions.Populate()
 at Microsoft.Exchange.Services.OData.ODataContext..ctor(HttpContext httpContext, Uri requestUri, ServiceModel serviceModel, ODataPathWrapper odataPath, ODataUriParser odataUriParser)
 at Microsoft.Exchange.Services.OData.Web.RequestBroker.InitializeODataContext()
 at Microsoft.Exchange.Services.OData.Web.RequestBroker.Process()",
      "internalexception": {
        "message": "A binary operator with incompatible types was detected. Found operand types 'Edm.DateTimeOffset' and 'Edm.Int32' for operator kind 'Equal'.",
        "type": "Microsoft.OData.Core.ODataException",
        "stacktrace": " at Microsoft.OData.Core.UriParser.Parsers.BinaryOperatorBinder.PromoteOperandTypes(BinaryOperatorKind binaryOperatorKind, SingleValueNode& left, SingleValueNode& right)
 at Microsoft.OData.Core.UriParser.Parsers.BinaryOperatorBinder.BindBinaryOperator(BinaryOperatorToken binaryOperatorToken)
 at Microsoft.OData.Core.UriParser.Parsers.MetadataBinder.Bind(QueryToken token)
 at Microsoft.OData.Core.UriParser.Parsers.FilterBinder.BindFilter(QueryToken filter)
 at Microsoft.OData.Core.UriParser.ODataUriParser.ParseFilterImplementation(String filter, IEdmType elementType, IEdmNavigationSource navigationSource)
 at Microsoft.OData.Core.UriParser.ODataUriParser.ParseFilter()
 at Microsoft.Exchange.Services.OData.Web.ODataQueryOptions.Populate()"
      }
    }
  }
}

这是我尝试过的所有事情:

[的ressource] = https://outlook.office365.com/

  

url:[ressource] EWS / OData / Me / Events?$ filter = Start%20eq%20DateTime' 2012-05-29T09:13:28'

     

url:[ressource] EWS / OData / Me / Events?$ filter = Start%20eq%20DateTime' 20141231'

     

url:[ressource] EWS / OData / Me / Events?$ filter = month(Start)%20eq%2012

我已经尝试过字符串字段上的$ filter或字段 Start 上的$ select,它完美运行所以我认为我的错误是由日期格式引起的,但我不是&# 39;知道如何解决它,所以如果有人可以帮助我,那就太棒了!

谢谢!

3 个答案:

答案 0 :(得分:3)

过滤日期确实有效,但您无法在OData v4规范中执行所有操作。例如,这些对我有用:

/Me/Events?$filter=Start eq 2014-08-28T21:00:00Z
/Me/Events?$filter=Start ge 2014-08-28T21:00:00Z

添加" DateTime"在它面前使它失败。与月份功能相同。如果你坚持使用上面的格式,它应该适合你。

答案 1 :(得分:2)

在O365 REST API的V2中,您应该使用:

angular-material: 1.1.3 ---> 1.0.0

更多信息https://msdn.microsoft.com/en-us/office/office365/api/complex-types-for-mail-contacts-calendar#filter-requests

答案 2 :(得分:0)

嗨,无论你想从收件箱中提取什么,只需增加顶部= 100或更多。

https://outlook.office365.com/api/v2.0/me/MailFolders/Inbox/messages/?%24select=CreatedDateTime%2cLastModifiedDateTime%2cChangeKey%2cCategories%2cReceivedDateTime%2cSentDateTime%2cHasAttachments%2cSubject%2cBody%2cImportance%2cParentFolderId%2cSender%2cFrom%2cToRecipients%2cCcRecipients%2cBccRecipients%2cReplyTo%2cConversationId%2cIsDeliveryReceiptRequested%2cIsReadReceiptRequested%2cIsRead%2cIsDraft%2cWebLink&%24top=100&%24skip=0"