获取具有由加载项设置的自定义属性的事件 [英] Get events that have an custom property set by an add-in

查看:18
本文介绍了获取具有由加载项设置的自定义属性的事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题是 通过 Microsoft Graph 在 Outlook 加载项中设置自定义属性.

我的 Outlook Office.js 插件正在向事件添加一些自定义属性.它按预期工作,我可以使用 Microsoft Graph 通过以下 GET 请求访问这些属性:

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')

但现在我尝试通过将此类正文发布到推送通知端点 (/v1.0/subscriptions) 来订阅推送通知:

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"
  }

但我得到了:

{
  "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"
    }
  }
}

尝试将请求中的资源设置为非转义,但结果相同,接下来我尝试的是 $filter 功能,因此使用 MS Graph 资源管理器以以下格式获取请求:

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')

但出现以下错误:

{
    "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"
        }
    }
}

这是否意味着我还必须按值过滤而不仅仅是 id?

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?

当我按照我得到的答案中的建议将 id 更改为 PropertyId 时:

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:

现在,当我添加按 value 过滤时,它可以工作了:

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

不尝试通过 value 过滤,而是使用不相等的 ne 运算符:

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.

推荐答案

经过几次尝试,我找到了一种方法来过滤具有自定义属性的事件/消息,而不管它的值是:

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)

添加的重要部分是 and ep/value ne null,而像 and ep/value ne 'fooo' 这样的东西不起作用,它只是返回了所有内容.

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.

这篇关于获取具有由加载项设置的自定义属性的事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆