Removing subscription to “Planned Maintenance” ema

2019-08-24 23:04发布

Using the REST API, How do I turn off the setting for email notification of "Planned Maintenance"? I have hundreds of user profiles I need to turn this setting off on.

Thanks for any help here!

1条回答
太酷不给撩
2楼-- · 2019-08-24 23:35

To “turn off” the Subscriptions - Planned Maintenance, you have to do user by user, the same that the customer portal because in rest api you cannot do for all users, but you can try to ¨turn off¨ all the users subscriptions using programing language doing your own code.

Here there is a example code in python to ¨turn off¨ all the users Subscriptions - Planned Maintenance

"""
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))

To ¨turn on¨ you just need to change the attribute ¨active¨ to 1.

Or you can ¨turn off¨ user by user using the followings rest api examples:

Method: POST

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

Body: Json

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

Reference:

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

Or you can use this other rest api:

Method: Post

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

Body: Json

{
  "parameters":[

    "PLANNED_MAINTENANCE",
                0
  ]
}

Reference:

https://softlayer.github.io/reference/services/SoftLayer_User_Customer/updateNotificationSubscriber/
查看更多
登录 后发表回答