Search code examples
microsoft-graph-apioffice-jsoutlook-restapioutlook-web-addins

Get events that have an custom property set by an add-in


This question is a follow-up to Get custom property set in Outlook Add-In via Microsoft Graph.

My Outlook Office.js add-in is adding some custom properties to an event. It works as expected and I can access those properties using Microsoft Graph, with following GET request:

/v1.0/me/events/{event-id}?$expand=SingleValueExtendedProperties($filter=id%20eq%20'String%20{00020329-0000-0000-C000-000000000046}%20Name%20cecp-b7ff386a-234a-4a38-84bc-e5ae4684b7af')

But now I try to subscribe to push notifications by posting such body to the push notifications endpoint (/v1.0/subscriptions):

  {
    changeType: "created,updated,deleted",
    notificationUrl: `[...my url...]`,
    resource: `/users/${userData.id}/events?$filter=singleValueExtendedProperties/any(ep%3A%20ep%2Fid%20eq%20'String%20{00020329-0000-0000-C000-000000000046}%20Name%20cecp-b7ff386a-234a-4a38-84bc-e5ae4684b7af')`,
    expirationDateTime: tomorrow,
    clientState: "SecretClientState"
  }

But I'm getting:

{
  "error": {
    "code": "ExtensionError",
    "message": "Operation: Create; Exception: [Status Code: BadRequest; Reason: Bad Request]",
    "innerError": {
      "request-id": "01dcece6-0103-4bef-8231-e9ab9480402a",
      "date": "2017-04-04T20:20:58"
    }
  }
}

Tried to set the resource in the request unescaped, but with same result, next thing I tried is the $filter functionality, so did a get request in following format using the MS Graph explorer:

/v1.0/me/events/?$filter=singleValueExtendedProperties/any(ep%3A%20ep%2Fid%20eq%20'String%20{00020329-0000-0000-C000-000000000046}%20Name%20cecp-b7ff386a-234a-4a38-84bc-e5ae4684b7af')

but got following error:

{
    "error": {
        "code": "ErrorInvalidUrlQueryFilter",
        "message": "The filter expression for $filter does not match to a single extended property and a value restriction.",
        "innerError": {
            "request-id": "aca7c8ed-6e30-4490-8feb-7f1d2aed6b88",
            "date": "2017-04-04T20:38:28"
        }
    }
}

does it mean that I also have to filter by value and not only id?

That would be an issue because I want the events that have the property set, but I don't know the value beforehand, I want to read it after I get a push notification.

Is there a way to get events which simply have a custom property set by my add-in, and subscribe to push notifications for events which has this custom property?

EDIT:

When I change id to PropertyId as suggested in the answer I'm getting:

{
    "error": {
        "code": "BadRequest",
        "message": "Could not find a property named 'PropertyId' on type 'microsoft.graph.singleValueLegacyExtendedProperty'.",
        "innerError": {
            "request-id": "1d3db71e-6ee2-4680-9317-64687813c52a",
            "date": "2017-04-05T13:49:45"
        }
    }
}

EDIT-2:

Now when I add filtering by value, it works:

/v1.0/me/events/?$filter=singleValueExtendedProperties/any(ep: ep/id eq 'String {00020329-0000-0000-C000-000000000046} Name cecp-b7ff386a-234a-4a38-84bc-e5ae4684b7af' and ep/value eq 'foo')

but I wan't all the events with that property regardless the value of it...

EDIT-3

No trying by filtering by value but using the non-equal ne operator:

/v1.0/me/events/?$filter=singleValueExtendedProperties/any(ep: ep/id eq 'String {00020329-0000-0000-C000-000000000046} Name cecp-b7ff386a-234a-4a38-84bc-e5ae4684b7af' and ep/value ne 'Foo')

it seems to work, but this time it looks like it just ignores the filter and returns all events, with and without that custom property set from the add-in.


Solution

  • After several tries I found a way to filter for events/messages that have a custom property regardless it's value:

    https://graph.microsoft.com/v1.0/me/events/?$filter=singleValueExtendedProperties/any(ep: ep/id eq 'String {00020329-0000-0000-C000-000000000046} Name cecp-b7ff386a-234a-4a38-84bc-e5ae4684b7af' and ep/value ne null)
    

    with the added important part being and ep/value ne null, whereas something like and ep/value ne 'fooo' didn't work, it just returned everything.

    Above filtering works also for filtering of events for which we want subscribe to push events.