获取具有外接程序设置的自定义属性的事件 [英] Get events that have an custom property set by an add-in

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

问题描述

此问题是对通过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资源管理器以以下格式获取了get请求:

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天全站免登陆