删除订阅“计划维护”电子邮件通知

时间:2018-05-04 22:35:48

标签: ibm-cloud-infrastructure

使用REST API,如何关闭“计划维护”电子邮件通知的设置? 我需要关闭此设置的数百个用户配置文件。

感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

要“关闭”订阅 - 计划维护,您必须逐个用户执行,与客户门户网站相同,因为在休息API中您无法为所有用户执行此操作, 但你可以尝试使用编程语言来完成所有用户订阅,并使用你自己的代码。

这里有一个示例代码在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))

要“开启”,您只需要将属性“活动”更改为1。

或者你可以通过以下方式使用以下方式关闭用户:api示例:

方法:POST

https://[username]:[apiKey]@api.softlayer.com/rest/v3/SoftLayer_User_Customer/[userId]/updateSubscriberDeliveryMethod

身体:Json

{
  "parameters":[
    "PLANNED_MAINTENANCE",
    [
                "EMAIL"
                ],
    0
  ]
}

参考:

https://softlayer.github.io/reference/services/SoftLayer_User_Customer/updateSubscriberDeliveryMethod/

或者你可以使用这个其他的api:

方法:发布

https://[username]:[apiKey]@api.softlayer.com/rest/v3/SoftLayer_User_Customer/[userId]/updateNotificationSubscriber

身体:Json

{
  "parameters":[

    "PLANNED_MAINTENANCE",
                0
  ]
}

参考:

https://softlayer.github.io/reference/services/SoftLayer_User_Customer/updateNotificationSubscriber/