OData of Outlook Event List cannot order by "Id"

Viewed 409

I tried to get a list of events from Microsoft Graph following this documentation.

I would like to get the list with order by lastModifiedDateTime and then id.

Here is the sample query:

var getResource = string.Format("/me/calendar/events/?$filter=lastModifiedDateTime ge {0}&$orderBy=lastModifiedDateTime, id", XmlConvert.ToString(updatedMin, XmlDateTimeSerializationMode.Utc));

However, when I executed it, it results an error:

{
  "error": {
    "code": "ErrorInvalidProperty",
    "message": "The property 'Id' does not support filtering.",
    "innerError": {
      "request-id": "bb56a0d0-46f3-4b7c-80bd-043a0b3fd8b5",
      "date": "2018-09-17T15:23:40"
    }
  }
}

In fact, I didn't set the Id within $filter, but instead, I set it as $orderby.

When I tried to exclude the Id from $orderby, it works. Here is the working query:

var getResource = string.Format("/me/calendar/events/?$filter=lastModifiedDateTime ge {0}&$orderBy=lastModifiedDateTime", XmlConvert.ToString(updatedMin, XmlDateTimeSerializationMode.Utc));

Anyone has an idea on how to order the list based on Id as well?

1 Answers

You cannot order by id, nor would it make any sense to do so. The id is a hashed combination of several properties (subject, path, etc.). As such, their value is neither orderable or human-readable.

This, for example, is an actual id value:

AAMkAGVmMDEzMTM4LTZmYWUtNDdkNC1hMDZiLTU1OGY5OTZhYmY4OABGAAAAAAAiQ8W967B7TKBjgx9rVEURBwAiIsqMbYjsT5e-T7KzowPTAAAAAAENAAAiIsqMbYjsT5e-T7KzowPTAACNM9xPAAA=

Also, I strongly recommend using the Microsoft Graph .NET Client rather than rolling your own. It will help reduce the learning curve and give you more readable code:

await graphClient.Me
   .Calendar
   .Events
   .Request()
   .Filter("lastModifiedDateTime ge {dateTime}")
   .OrderBy("lastModifiedDateTime") 
   .GetAsync();
Related