Notification Service – 示例
发送内容简单的电子邮件
使用以下端点发送一封简单的电子邮件:
POST /api/notification/v3/publisher/messages
示例请求有效载荷:
{
"body":
{
"message":"message"
},
"recipientsTo":"mail@provider.com;mail@provider-B.com",
"from":"name",
"subject":"subject"
}
recipientTo
字段中可以用分号分隔多个收件人。
创建电子邮件模板
要使用模板发送电子邮件,首先必须创建收件人、电子邮件内容和通信类别。
创建收件人
使用以下端点注册收件人:
POST /api/notification/v3/recipient/
有关 addresstypeid
的有效输入,请参见 Notification Service API 规范中的 /recipient/addresstype
。
示例请求:
{
"recipientname" : "name",
"recipientdetail" : [ {
"address" : "mail@provider.com",
"addresstypeid" :2
},
{
"address" : "mail@provider-B.com",
"addresstypeid" :1
} ]
}
示例响应:
806
响应中包含创建的收件人的 recipientID
。存储此信息,并作为以下 API 调用的参考。
为电子邮件内容创建模板
使用以下端点创建电子邮件内容模板:
POST /api/notification/v3/template/
有关请求结构和创建占位符的详细信息,请参见此端点的 API。 有关 commChannelId
的有效输入,请参见 Notification Service API 规范中的 /communicationchannel/
。
示例模板:
<html xmlns:th="http://www.thymeleaf.org" th:inline="text" th:remove="tag">
你好 [[${name}]]。更多详情,请点击 <a th:href="${actualurl}">[[${url}]]</a>
</html>
在此模板中,收件人的名称和包含的 URL 是已定义的占位符。
示例响应:
{
"templatesetId":111,
"templatesetName":"TestTemplateForEmail",
"templateList": [
{
"templateId":412,
"commChannelId":1,
"commChannelName":"Email"
}
]
}
存储 templatesetId
和 templateId
的值,并作为以下 API 调用的参考。
创建通信类别
使用以下端点创建通信类别:
POST /api/notification/v3/communicationcategories/
在以下示例请求中,重复使用前面步骤中创建的 recipientID
、templatesetId
和 templateId
。
示例请求:
{
"msgCategoryName": "category name",
"subject": "subject",
"priority":1,
"from":"name",
"recipients":[
{
"recipientId":807,
"position":"TO"
}
],
"templates":[
{
"templateId":412,
"templatesetId":111,
"commChannelName":"Email"
}
]
}
示例响应:
642
响应中包含生成的通信类别的 categoryID
。存储此信息,并作为以下 API 调用的参考。
使用模板发送电子邮件
使用以下端点按照模板发送电子邮件:
POST /api/notification/v3/publisher/messages
请求必须提供 categoryId
,并为电子邮件内容模板占位符定义其值。在创建期间定义通信类别的默认收件人。recipientTo
字段可以用分号分隔多个收件人。
示例请求:
{
"body" : {
"placeholderkey1" : "value1",
"placeholderkey2" : "value2",
},
"recipientsTo" : "mail@provider.com",
"messageCategoryId" :642
}
广播电子邮件
使用以下端点向租户的所有用户,包括子租户的用户广播未加密的电子邮件:
POST /api/notification/v3/broadcastEmails?broadcastType=all
通过密送的方式隐藏广播电子邮件的收件人。
广播一封简单的电子邮件的示例请求:
{
"body":
{
"message":"Simple broadcast Email content"
},
"from":"name",
"subject":"subject"
"priority":3
}
使用模板广播电子邮件的示例请求:
{
"body":
{
"placeholderkey1" : "value1",
"placeholderkey2" : "value2",
},
"messageCategoryId" :642,
"subject":"subject"
}
根据API规范中的说明将电子邮件广播请求中的broadcastType
参数修改为其他用户组。
使用模板发送短信通知
Notification Service 提供向移动设备发送短信通知的功能。要使用模板发送短信通知,必须首先创建收件人、消息内容和通信类别。
创建带有短信通知详细信息的收件人
使用以下端点注册收件人:
POST /api/notification/v3/recipient/
请参考 Notification Service API 规范 的 /recipient/addresstype
为 addresstypeid
提供有效输入。
示例请求:
{
"recipientname" : "User",
"recipientdetail" : [ {
"address" : "+911234567890",
"addresstypeid" : 4
},
{
"address" : "+497777777777",
"addresstypeid" : 5
} ]
}
示例响应:
100795
创建短信通知内容模板
使用以下端点创建短信内容模板:
POST /api/notification/v3/template/
有关请求结构和创建占位符的详细信息,请参阅此端点的 API 。
请参考 Notification Service API 规范 的 /communicationchannel/
为 commChannelId
提供有效输入。
示例模板
<html xmlns:th="http://www.thymeleaf.org" th:inline="text" th:remove="tag">
Dear [[${name}]], Welcome to SMS service feature of Communication Service Mindsphere.(Hardware Activation)
</html>
在此模板中,收件人的名称是已定义的占位符。以上 html 被保存为 SMS.html 并作为templateFiles
参数添加到请求中。
示例请求:
{
"templateParam": [{
"paramName": "Name",
"defaultValue": "Mindsphere User",
"placeHolderName": "name",
"paramTypeId": 4
}],
"templatesetName": "TemplateForSMS",
"templateChannelAndFile": [{
"communicationChannel": 2,
"fileName": "SMS.html"
}]
}
示例响应:
{
"templatesetId": 19489,
"templatesetName": "TemplateForSMS",
"templateList": [
{
"templateId": 22578,
"commChannelId": 2,
"commChannelName": "SMS"
}
]
}
保存 templatesetId
和 templateId
的值为以下 API 调用的引用。
创建通信类别
使用以下端点创建通信类别:
POST /api/notification/v3/communicationcategories/
在下面的示例请求中,复用前面步骤中创建的 recipientId
, templatesetId
and templateId
。短信通知的主题必须在请求的相应字段中提供。
示例请求:
{
"msgCategoryName" : "Category for SMS",
"recipients" : [ {
"recipientId" : 100795
} ],
"templates" : [ {
"templateId" : 22578,
"commChannelName" : "SMS",
"templatesetId" : 19489
} ]
}
示例响应:
29675
响应包含生成的通信类别的 categoryId
。将此信息保存为以下 API 调用的参考。
触发通知
要触发准备好的通知,请使用以下端点:
POST /api/notification/v3/publisher/messages
请求必须提供 categoryId
并为短信内容的模板占位符定义值。通信类别的默认收件人在其创建期间定义。
示例请求:
{
"body": {
"name": "MDSP User"
},
"messageCategoryId": 29675
}
使用模板发送推送通知
Notification Service 提供了向移动设备发送推送通知的功能。要使用模板发送推送通知,首先必须创建收件人、内容和通信类别。
使用推送通知详情创建收件人
使用以下端点注册收件人:
POST /api/notification/v3/recipient/
有关 addresstypeid
的有效输入,请参见 Notification Service API 规范中的 /recipient/addresstype
。 请在请求的 address
字段中提供以下信息:
appId
:GCM 连接服务器签发的唯一设备和应用特定 ID,允许客户端应用接收消息。serverApiKey
:存储在应用服务器上的唯一应用特定密钥,提供了对 Google 服务的授权访问applicationName
:发送通知的应用名称
示例请求:
{
"recipientname" :"PushNotificationTest",
"recipientdetail" : [{
"address" : {
"appId":"id",
"serverApiKey":"apiKey",
"applicationName":"app name"
},
"addresstypeid" :7
} ]
}
示例响应:
807
响应中包含创建的收件人的 recipientID
。存储此信息,并作为以下 API 调用的参考。
为推送通知内容创建模板
使用以下端点创建推送通知内容模板:
POST /api/notification/v3/template/
有关请求结构和创建占位符的详细信息,请参见此端点的 API。 有关 commChannelId
的有效输入,请参见 Notification Service API 规范中的 /communicationchannel/
。
示例模板:
<html xmlns:th="http://www.thymeleaf.org" th:inline="text" th:remove="tag">
你好 [[${name}]]。更多详情,请点击 <a th:href="${actualurl}">[[${url}]]</a>
</html>
在此模板中,收件人的名称和包含的 URL 是已定义的占位符。
示例响应:
{
"templatesetId":436,
"templatesetName":"TestTemplateForPushNotification12",
"templateList": [
{
"templateId":468,
"commChannelId":3,
"commChannelName":"Push Notification"
}
]
}
存储 templatesetId
和 templateId
的值,并作为以下 API 调用的参考。
创建通信类别
使用以下端点创建通信类别:
POST /api/notification/v3/communicationcategories/
在以下示例请求中,重复使用前面步骤中创建的 recipientID
、templatesetId
和 templateId
。请在请求的相应字段中提供推送通知的主题。
示例请求:
{
"msgCategoryName": "category name",
"subject": "subject",
"priority":1,
"from":"name",
"recipients":[
{
"recipientId":806,
"position":"TO"
}
] ,
"templates":[
{
"templateId":468,
"templatesetId":436,
"commChannelName":"Push Notification"
}
]
}
示例响应:
642
响应中包含生成的通信类别的 categoryID
。存储此信息,并作为以下 API 调用的参考。
触发通知
使用以下端点触发已设置好的通知:
POST /api/notification/v3/publisher/messages
请求必须提供 categoryId
,并为推送内容模板占位符定义其值。在创建期间定义通信类别的默认收件人。
示例请求:
{
"body" :
{
"placeholderkey1" : "value1",
"placeholderkey2" : "value2",
},
"messageCategoryId":642
}
从黑名单中删除被阻止的电子邮件地址
租户管理员可以使用以下端点:
DELETE /api/notification/v3/communicationcategories/bouncedEmailIds
示例请求:
{
"emailList" : ["mail@provider.com"]
}
提示
使用以下端点列出所有被列入黑名单的电子邮件地址:
GET /api/notification/v3/communicationcategories/bouncedEmailIds
说明
IoT Value Plan 租户将无法直接访问列入黑名单的端点。这些租户可以通过技术支持来请求列入黑名单的电子邮件。
还有问题?
除非另行声明,该网站内容遵循MindSphere开发许可协议.