您好:出于某些原因,我所有的用户(销售,市场营销,财务等)都收到有关计划外事件,计划内维护等的电子邮件通知,并且抱怨“垃圾邮件”消息的数量。使用API,我看到了类Email_Subscription,并且可以列出与用户的门户网站/帐户/用户/电子邮件首选项屏幕相对应的所有对象类型,但无法弄清楚如何按用户大规模禁用电子邮件通知。有人在Python中有一个示例吗?另外,我认为这与User_Notifications类不同并且分开,对吗?谢谢!
答案 0 :(得分:1)
您可以尝试使用此python示例代码按用户禁用电子邮件通知订阅者用户。
"""
UpdateNotificationSubscriber
Update the active status for a notification that the user is subscribed to. A notification along with an active flag
can be supplied to update the active status for a particular notification subscription.
Important manual pages:
https://softlayer.github.io/reference/services/SoftLayer_User_Customer/
https://softlayer.github.io/reference/services/SoftLayer_User_Customer/updateNotificationSubscriber/
License: http://sldn.softlayer.com/article/License
Author: SoftLayer Technologies, Inc. <sldn@softlayer.com>
"""
import SoftLayer
# For nice debug output:
from pprint import pprint as pp
# Your SoftLayer API username and key.
API_USERNAME = 'set me'
# Generate one at https://control.softlayer.com/account/users
API_KEY = 'set me'
userId = 11111
notificationKeyName = "PLANNED_MAINTENANCE"
active = 0
client = SoftLayer.create_client_from_env(
username=API_USERNAME,
api_key=API_KEY
)
try:
orderStatus = client['SoftLayer_User_Customer'].updateNotificationSubscriber(notificationKeyName, active, id=userId)
print(orderStatus)
except SoftLayer.SoftLayerAPIError as e:
pp('Unable to update the user notification subscriber faultCode=%s, faultString=%s'
% (e.faultCode, e.faultString))
要禁用其他类型的通知订阅者,例如计划外事件等,您只需替换所需通知的“ notificationKeyName”属性数据即可。
要启用通知订阅者,只需将“活动”属性更改为1。
要获取帐户中所有活动的通知订阅者,您可以使用以下rest api:
方法:GET
https://[username]:[apiKey]@api.softlayer.com/rest/v3.1/SoftLayer_Account/getActiveNotificationSubscribers?objectMask=mask[notification]
您将收到类似以下示例的答复:
{
"active": 1,
"createDate": "2017-03-09T16:17:09-06:00",
"id": 22222,
"modifyDate": "2017-03-09T16:17:09-06:00",
"notificationId": 68,
"notificationSubscriberTypeId": 2,
"notificationSubscriberTypeResourceId": 556633,
"notification": {
"id": 68,
"keyName": "UNPLANNED_INCIDENT",
"name": "Unplanned Incident"
}
},
使用“ KeyName”数据替换python代码中的“ notificationKeyName”属性。
或者,如果您想了解所有用户的通知订阅者,则可以使用此rest api:
方法:GET
https://[username]:[apikey]@api.softlayer.com/rest/v3.1/SoftLayer_Account/getUsers?objectMask=mask[id,username,notificationSubscribers[notification]]
如果要为所有用户禁用通知订阅者,则可以尝试使用以下python代码:
"""
UpdateNotificationSubscriber
Update the active status for a notification that the user is subscribed to. A notification along with an active flag
can be supplied to update the active status for a particular notification subscription.
Important manual pages:
https://softlayer.github.io/reference/services/SoftLayer_User_Customer/
https://softlayer.github.io/reference/services/SoftLayer_User_Customer/updateNotificationSubscriber/
License: http://sldn.softlayer.com/article/License
Author: SoftLayer Technologies, Inc. <sldn@softlayer.com>
"""
import SoftLayer
import json
USERNAME = 'set me'
API_KEY = 'set me'
notificationKeyName = "PLANNED_MAINTENANCE"
active = 0
client = SoftLayer.Client(username=USERNAME, api_key=API_KEY)
accountService = client['SoftLayer_Account']
customerService = client['SoftLayer_User_Customer']
try:
users = accountService.getUsers()
for user in users:
id = user['id']
result = customerService.updateNotificationSubscriber(notificationKeyName, active, id=id)
print(json.dumps(result, sort_keys=True, indent=2, separators=(',', ': ')))
except SoftLayer.SoftLayerAPIError as e:
print("Unable to change the subscription notification. faultCode=%s, faultString=%s" % (e.faultCode, e.faultString))
另一个可以在其中找到更多示例的链接:
Removing subscription to "Planned Maintenance" email notifications
Subscribe users to notifications via Soft Layer API
要与控制门户网站一样禁用电子邮件首选项,可以使用以下python代码示例:
"""
Disable email subscription.
Important manual pages:
https://softlayer.github.io/reference/services/SoftLayer_Email_Subscription/disable/
"""
import SoftLayer
# For nice debug output:
from pprint import pprint as pp
# Your SoftLayer API username and key.
API_USERNAME = 'set me'
# Generate one at https://control.softlayer.com/account/users
API_KEY = 'set me'
emailSubscriptionId = 1
client = SoftLayer.create_client_from_env(
username=API_USERNAME,
api_key=API_KEY
)
try:
billingObjects = client['SoftLayer_Email_Subscription'].disable(id = emailSubscriptioId)
print(billingObjects)
except SoftLayer.SoftLayerAPIError as e:
pp('Unable to disable the email subscription faultCode=%s, faultString=%s'
% (e.faultCode, e.faultString))
“ emailSubscriptionId”按从页面顶部到底部的顺序排列,例如第一个选项为“订购”,其事件类型为“正在审阅的订单”具有emailSubscriptionId = 1,另一个选项“计划维护”,其事件为“ High Impact”具有emailSubscriptionId = 8,最后一个选项是emailSubscriptionId = 16
参考:
https://softlayer.github.io/reference/services/SoftLayer_Email_Subscription/disable/