0

We want to receive change notifications from our user's Outlook calendars. We'd like to limit those notifications to only those calendar items that contain our custom property.

CODE WHICH CREATES CALENDAR EVENT

private static async Task<Event> CreateAppointmentAsync(GraphServiceClient graphClient)
{

    var newEvent = new Microsoft.Graph.Event
    {
        Subject = "Test Calendar Appointmnt",
        Start = new DateTimeTimeZone() { TimeZone = TimeZoneInfo.Local.Id, DateTime = "2020-11-21T21:00:00" },
        End = new DateTimeTimeZone() { TimeZone = TimeZoneInfo.Local.Id, DateTime = "2020-11-21T22:00:00" },
        Location = new Location() { DisplayName = "Somewhere" },
        Body = new ItemBody { Content = "Some Random Text" },

    };

    Microsoft.Graph.Event addedEvent;
    try
    {
        newEvent.SingleValueExtendedProperties = new EventSingleValueExtendedPropertiesCollectionPage();
        newEvent.SingleValueExtendedProperties.Add(new SingleValueLegacyExtendedProperty { Id = "String {00020329-0000-0000-C000-000000000046} Name CompanyID", Value = "12345" });


        addedEvent = await graphClient.Me.Calendar.Events.Request().AddAsync(newEvent);

   

    }
    catch (Exception e)
    {
        throw e;
    }


    return addedEvent;

  

}

THE SUBSCRIPTION CODE SNIPPET

var subscription = new Subscription
{
    ChangeType = "created",
    NotificationUrl ="<OUR-URL>",                                   
    Resource = "me/events/?$filter=singleValueExtendedProperties/any(ep: ep/id eq 'String {00020329-0000-0000-C000-000000000046} Name CompanyID' and ep/value ne null)",
    ExpirationDateTime = DateTimeOffset.Parse("2020-11-13T18:23:45.9356913Z"),
    ClientState = "custom_data_state",
    LatestSupportedTlsVersion = "v1_2"
};

The subscription is created successfully, but notifications are not being sent for those items containing the specific custom property described above.

ezG
  • 391
  • 1
  • 17
  • @Shiva-MSFTIdentity, according to this post [Get events that have an custom property set by an add-in](https://stackoverflow.com/questions/43217399/get-events-that-have-an-custom-property-set-by-an-add-in), the ability to filter notifications based on custom events is possible. Is it not possible for calendar events? – ezG Nov 13 '20 at 16:21

1 Answers1

0

It turns out I was only capturing the "created" notification. I neglected to add "updated" and "deleted".

I was testing with an event that already existed in my calendar. No events were being fired because I didn't create the subscription to detect updates and deletes.

Here is the corrected subscription:

var subscription = new Subscription
{
    ChangeType = "created,updated,deleted",
    NotificationUrl ="<OUR-URL>",                                   
    Resource = "me/events/?$filter=singleValueExtendedProperties/any(ep: ep/id eq 'String {00020329-0000-0000-C000-000000000046} Name CompanyID' and ep/value ne null)",
    ExpirationDateTime = DateTimeOffset.Parse("2020-11-13T18:23:45.9356913Z"),
    ClientState = "custom_data_state",
    LatestSupportedTlsVersion = "v1_2"
};
ezG
  • 391
  • 1
  • 17