3

Situation:

We have an old application that is creating events in outlook (via MAPI). To identify the events the custom property 'CTOID' is set with a specific value by which the events can be found again.

For a newer application we would like to use the Graph API but the application should still be able to read/find the events created by the old application. So I created a test event with a specific CTOID and I can already use the graph client to get the mentioned event with the according property and its value (queryOptions is just some start-/enddate restrictions).

// Initialize the GraphServiceClient.
GraphServiceClient client = await m_MicrosoftGraphClient.GetGraphServiceClient();

// Load user events.
var request = client.Users[userId].CalendarView.Request(queryOptions).Expand("singleValueExtendedProperties($filter=id%20eq%20'Double%20{00020329-0000-0000-C000-000000000046}%20Name%20CTOID')");
var result = await request.GetAsync();
var calendarEvents = result.CurrentPage;

Result:

The event gets fetched correctly including the value for the CTOID property. enter image description here

Problem:

I can "Expand" events so they contain the value for the CTOID property. But how do I find an event with a specific CTOID value? And specifically, how do I do this with the Graph client in C#?

According to the documentation and this Stackoverflow post, the following REST call should work:

GET /users/{id|userPrincipalName}/events?$filter=singleValueExtendedProperties/Any(ep: ep/id eq '{id_value}' and ep/value eq '{property_value}')

So I tried this in the online Graph Explorer:

https://graph.microsoft.com/v1.0/users/[MY_USER_ID]/events?$filter=singleValueExtendedProperties/Any(ep: ep/id eq 'Double {00020329-0000-0000-C000-000000000046} Name CTOID' and ep/value eq '229236')

But all I get as response is:

{
    "error": {
        "code": "ErrorInvalidUrlQueryFilter",
        "message": "The filter expression for $filter does not match to a single extended property and a value restriction.",
        "innerError": {
            "date": "2020-08-03T12:44:05",
            "request-id": "33e82c77-92ea-4865-a8d0-00cfc2f99154"
        }
    }
}

What am I doing wrong? I'm out of ideas and any help would be greatly appreciated. (Also if you have any idea how to do this with the Graph client in C# and not just the bare REST call).

Additional Information:

Don't know if it's important, but the following permissions are set for our application: enter image description here

InD
  • 239
  • 2
  • 12

1 Answers1

3

In your filter you need to cast the value to a Double eg

https://graph.microsoft.com/v1.0/users/[MY_USER_ID]/events?$filter=singleValueExtendedProperties/Any(ep: ep/id eq 'Double {00020329-0000-0000-C000-000000000046} Name CTOID' and cast(ep/value, Edm.Double) eq 229236)

For anything other then a String in a filter you need to do this

Glen Scales
  • 20,495
  • 1
  • 20
  • 23
  • Ah, this works perfectly, thank you so much! The MS Documentation (see link in the question above) seems to be very missleading in this case. The section "GET resource instances that include numeric extended properties matching a filter" does not mention anything about casting. Strange. – InD Aug 04 '20 at 07:36