Search code examples
microsoft-graph-apimicrosoft-graph-sdksmicrosoft-graph-calendar

Search for an event according to a specific value of a singleValueExtendedProperty


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


Solution

  • 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