Search code examples
ms-officeodataexchangewebservicesoffice365

Odata $filter for the date in the Office 365 REST API


I'm trying to retrieve events for a user from its Office 365 account using the REST API but filtered by the field "Start". For instance, retrieve all the events that will happen after the date: 2014-08-29T09:13:28' but i'm always retrieving this error message

{
  "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()"
      }
    }
  }
}

Here all the thing i've tried:

[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

And i've tried the $filter on string field or the $select on the field Start and it worked perfectly so i think my error is caused by the date format but i don't know how to solve it, so if anybody could help me on that, it woud be great!

Thank you!


Solution

  • Filtering on dates does work, but you can't do everything in the OData v4 spec. For example, these all work for me:

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

    Adding the "DateTime" in front of it makes it fail. The same with the month function. If you stick with the format above it should work for you.