Outlook Rest API 推送通知:根据 outlook 加载项设置的特定自定义 属性 过滤通知
Outlook Rest API push notifications: Filter the notifications based on specific custom property set by outlook add-in
我按照 中提到的相同步骤,根据 outlook 加载项设置的自定义属性过滤推送通知事件。
以下是我订阅推送通知时使用的资源link。
https://outlook.office.com/api/v2.0/me/events/?$filter=SingleValueExtendedProperties%2FAny(ep%3A%20ep%2FPropertyId%20eq%20'String%20{00020329-0000-0000-C000-000000000046}%20Name%20cecp-7e248e5e-204e-4e2b-aa0f-788af20fc21c'%20and%20ep%2FValue%20ne%20null)
它正在过滤具有由加载项设置的自定义属性的日历项目,而不管它是什么自定义 属性。
通过查看此资源 link,我们可以说没有提到自定义 属性 名称的地方。但是我的加载项为日历项设置了多个自定义属性。我想过滤所有具有特定自定义 属性 的日历项目。例如,我的加载项将以下任何一项自定义 属性 设置为基于业务登录的日历。
自定义 属性 1:
var item = Office.context.mailbox.item;
item.loadCustomPropertiesAsync((result) => {
const props = result.value;
props.set("my_prop_one", "test_value_one");
props.saveAsync((saveResult) => console.log("Successfull"));
});
自定义 属性 2:
var item = Office.context.mailbox.item;
item.loadCustomPropertiesAsync((result) => {
const props = result.value;
props.set("my_prop_two", "test_value_tw");
props.saveAsync((saveResult) => console.log("Successful"));
});
现在我想过滤所有具有自定义 属性 my_prop_one
.
的日历项目
编辑 1:
正如@Jason Johnston 在其中一条评论中所建议的,我使用 MFCMapi 交叉验证了 属性 名称及其 GUID。 属性 名称及其 GUID 值均正确。
自定义属性meetingsetby
的MFCMapi数据。
然后我从 MFCMapi 收集了数据并准备了下面的 url 来过滤具有自定义 属性 meetingsetby
且其值为 webex
.[=36 的日历项目=]
https://outlook.office.com/api/v2.0/Me/Events?$filter=SingleValueExtendedProperties%2FAny(ep%3A%20ep%2FPropertyId%20eq%20'String%20{00020329-0000-0000-C000-000000000046}%20Name%20meetingsetby'%20and%20ep%2FValue%20eq%20'webex')
下面是 postman
在我使用上述 url 进行 get 调用时的响应。
如您所见,即使有一个日历项具有自定义 属性 meetingsetby
和值 webex
.
,响应也有空列表
然后我使用 outlook Rest API 将 SingleValueExtendedProperty
设置为日历项,如 this post 中所述。以下是示例请求数据,
SingleValueExtendedProperty
的MFCMapi数据
然后我从 MFCMapi 收集了数据并准备了下面的 url 来过滤在上面的步骤中设置了 singleValueExtendedProperty
的日历项目。
https://outlook.office.com/api/v2.0/Me/Events?$filter=SingleValueExtendedProperties%2FAny(ep%3A%20ep%2FPropertyId%20eq%20'String%20{6666AA44-4659-4830-9070-00047EC6AC6E}%20Name%20RestApiSingleValueExtendedProperty'%20and%20ep%2FValue%20eq%20'Set this property using REST API')
下面是 postman
在我使用上述 url 进行 get 调用时的响应。
如您所见,我可以使用 singleValueExtendedProperty
成功过滤日历项目。但我的要求是过滤具有由我的 Outlook Web 加载项设置的特定自定义 属性 的日历项目。
任何 suggestion/answers 都非常欢迎。
加载项设置的自定义属性(使用 CustomProperties interface) are not equivalent to normal MAPI named properties. Essentially what the add-in APIs do is take all of your "custom properties", serialize them as a JSON payload, then save it in a single MAPI named property, which will have the name cecp-{some guid}
, and the property set GUID PS_PUBLIC_STRINGS {00020329-0000-0000-C000-000000000046}
. The {some-guid}
part of the name is equal to the Id
of your add-in. This is all specified in MS-OXCEXT section 2.2.5.
所以这里的最终结果是,你在CustomProperties
界面中设置的值不能使用$filter
,因为没有SingleValueExtendedProperty
具有那个名称和值。相反,只有一个名为 cecp-{some guid}
的 SingleValueExtendedProperty
,其字符串值是您通过 CustomProperties
界面设置的所有自定义道具的 JSON 序列化。
那你怎么能做你想做的事呢?好吧,回到原来的 URL,您可以通过执行
获取所有具有您的加载项设置的任何属性的消息
$filter=SingleValueExtendedProperties/Any
(ep: ep/PropertyId eq 'String {00020329-0000-0000-C000-000000000046}
Name cecp-7e248e5e-204e-4e2b-aa0f-788af20fc21c' and ep/Value ne null)
将 cecp-
之后的 GUID 替换为您的加载项的 GUID ID。
但是您当然只想找到将特定 属性 (meetingsetby
) 设置为特定值 (webex
) 的那些。不幸的是,我们的 API 在过滤 SingleValueExtendedProperties
时不支持子字符串搜索。因此,您需要做的是获取具有您的加载项设置的任何属性的所有消息,然后执行您自己的过滤逻辑以找到您想要的消息。所以基本上你会把它们加载到内存中,然后自己检查 属性 的值来找到你想要的。
您可以使用 $expand
子句确保 属性 的值包含在响应中。像这样:
?$filter=SingleValueExtendedProperties/Any
(ep: ep/PropertyId eq 'String {00020329-0000-0000-C000-000000000046}
Name cecp-7e248e5e-204e-4e2b-aa0f-788af20fc21c' and ep/Value ne null)
&$expand=SingleValueExtendedProperties($filter=PropertyId eq 'String
{00020329-0000-0000-C000-000000000046} Name cecp-7e248e5e-204e-4e2b-aa0f-788af20fc21c')
我按照
以下是我订阅推送通知时使用的资源link。
https://outlook.office.com/api/v2.0/me/events/?$filter=SingleValueExtendedProperties%2FAny(ep%3A%20ep%2FPropertyId%20eq%20'String%20{00020329-0000-0000-C000-000000000046}%20Name%20cecp-7e248e5e-204e-4e2b-aa0f-788af20fc21c'%20and%20ep%2FValue%20ne%20null)
它正在过滤具有由加载项设置的自定义属性的日历项目,而不管它是什么自定义 属性。 通过查看此资源 link,我们可以说没有提到自定义 属性 名称的地方。但是我的加载项为日历项设置了多个自定义属性。我想过滤所有具有特定自定义 属性 的日历项目。例如,我的加载项将以下任何一项自定义 属性 设置为基于业务登录的日历。
自定义 属性 1:
var item = Office.context.mailbox.item;
item.loadCustomPropertiesAsync((result) => {
const props = result.value;
props.set("my_prop_one", "test_value_one");
props.saveAsync((saveResult) => console.log("Successfull"));
});
自定义 属性 2:
var item = Office.context.mailbox.item;
item.loadCustomPropertiesAsync((result) => {
const props = result.value;
props.set("my_prop_two", "test_value_tw");
props.saveAsync((saveResult) => console.log("Successful"));
});
现在我想过滤所有具有自定义 属性 my_prop_one
.
编辑 1:
正如@Jason Johnston 在其中一条评论中所建议的,我使用 MFCMapi 交叉验证了 属性 名称及其 GUID。 属性 名称及其 GUID 值均正确。
自定义属性meetingsetby
的MFCMapi数据。
然后我从 MFCMapi 收集了数据并准备了下面的 url 来过滤具有自定义 属性 meetingsetby
且其值为 webex
.[=36 的日历项目=]
https://outlook.office.com/api/v2.0/Me/Events?$filter=SingleValueExtendedProperties%2FAny(ep%3A%20ep%2FPropertyId%20eq%20'String%20{00020329-0000-0000-C000-000000000046}%20Name%20meetingsetby'%20and%20ep%2FValue%20eq%20'webex')
下面是 postman
在我使用上述 url 进行 get 调用时的响应。
如您所见,即使有一个日历项具有自定义 属性 meetingsetby
和值 webex
.
然后我使用 outlook Rest API 将 SingleValueExtendedProperty
设置为日历项,如 this post 中所述。以下是示例请求数据,
SingleValueExtendedProperty
的MFCMapi数据
然后我从 MFCMapi 收集了数据并准备了下面的 url 来过滤在上面的步骤中设置了 singleValueExtendedProperty
的日历项目。
https://outlook.office.com/api/v2.0/Me/Events?$filter=SingleValueExtendedProperties%2FAny(ep%3A%20ep%2FPropertyId%20eq%20'String%20{6666AA44-4659-4830-9070-00047EC6AC6E}%20Name%20RestApiSingleValueExtendedProperty'%20and%20ep%2FValue%20eq%20'Set this property using REST API')
下面是 postman
在我使用上述 url 进行 get 调用时的响应。
如您所见,我可以使用 singleValueExtendedProperty
成功过滤日历项目。但我的要求是过滤具有由我的 Outlook Web 加载项设置的特定自定义 属性 的日历项目。
任何 suggestion/answers 都非常欢迎。
加载项设置的自定义属性(使用 CustomProperties interface) are not equivalent to normal MAPI named properties. Essentially what the add-in APIs do is take all of your "custom properties", serialize them as a JSON payload, then save it in a single MAPI named property, which will have the name cecp-{some guid}
, and the property set GUID PS_PUBLIC_STRINGS {00020329-0000-0000-C000-000000000046}
. The {some-guid}
part of the name is equal to the Id
of your add-in. This is all specified in MS-OXCEXT section 2.2.5.
所以这里的最终结果是,你在CustomProperties
界面中设置的值不能使用$filter
,因为没有SingleValueExtendedProperty
具有那个名称和值。相反,只有一个名为 cecp-{some guid}
的 SingleValueExtendedProperty
,其字符串值是您通过 CustomProperties
界面设置的所有自定义道具的 JSON 序列化。
那你怎么能做你想做的事呢?好吧,回到原来的 URL,您可以通过执行
获取所有具有您的加载项设置的任何属性的消息$filter=SingleValueExtendedProperties/Any
(ep: ep/PropertyId eq 'String {00020329-0000-0000-C000-000000000046}
Name cecp-7e248e5e-204e-4e2b-aa0f-788af20fc21c' and ep/Value ne null)
将 cecp-
之后的 GUID 替换为您的加载项的 GUID ID。
但是您当然只想找到将特定 属性 (meetingsetby
) 设置为特定值 (webex
) 的那些。不幸的是,我们的 API 在过滤 SingleValueExtendedProperties
时不支持子字符串搜索。因此,您需要做的是获取具有您的加载项设置的任何属性的所有消息,然后执行您自己的过滤逻辑以找到您想要的消息。所以基本上你会把它们加载到内存中,然后自己检查 属性 的值来找到你想要的。
您可以使用 $expand
子句确保 属性 的值包含在响应中。像这样:
?$filter=SingleValueExtendedProperties/Any
(ep: ep/PropertyId eq 'String {00020329-0000-0000-C000-000000000046}
Name cecp-7e248e5e-204e-4e2b-aa0f-788af20fc21c' and ep/Value ne null)
&$expand=SingleValueExtendedProperties($filter=PropertyId eq 'String
{00020329-0000-0000-C000-000000000046} Name cecp-7e248e5e-204e-4e2b-aa0f-788af20fc21c')