Hello: For some reason all of my users (sales, marketing, finance etc...) are receiving email notices about unplanned events, planned maintenance etc... and are complaining about the number of "spam" messages. Using the API I see class Email_Subscription and can list all object types which correspond to the portal/Account/Users/Email Preferences screen for a user but cannot figure out how to mass disable email notifications user by user. Anyone have an example in Python for this? Also, I think this is different and separate from the User_Notifications class, correct? Thanks!
1 Answers
You can try using this python example code to disable the email notifications subscriber user by user.
"""
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))
To disable another type of notification subscriber such as unplanned events, etc. you just have to replace the “notificationKeyName” attribute data for the notification you want.
To enable a notification subscriber, you just have to change the “active” attribute to 1.
To get all active notification subscribers in your account you can use this rest api:
Method: GET
https://[username]:[apiKey]@api.softlayer.com/rest/v3.1/SoftLayer_Account/getActiveNotificationSubscribers?objectMask=mask[notification]
You will get a response like this example:
{
"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"
}
},
Use the "KeyName" data to replace the "notificationKeyName " attribute in the python code.
Or if you want to know the notification subscribers for all the users you can use this rest api:
Method: GET
https://[username]:[apikey]@api.softlayer.com/rest/v3.1/SoftLayer_Account/getUsers?objectMask=mask[id,username,notificationSubscribers[notification]]
If you want to disable the notification subscriber for all the user you can try using the following python code:
"""
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))
Another links where can you find more examples:
Removing subscription to "Planned Maintenance" email notifications
Subscribe users to notifications via Soft Layer API
To disable the email preferences the same that the control portal you can use the following python code example:
"""
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))
The "emailSubscriptionId" comes in order from the top of the page to the bottom, it means e.g. the first option which is "Ordering" with the type of event "Order Being Reviewed" has the emailSubscriptionId = 1, another option "Planned Maintenance" with the event "High Impact" has the emailSubscriptionId = 8, the last one is emailSubscriptionId = 16.
Reference:
https://softlayer.github.io/reference/services/SoftLayer_Email_Subscription/disable/

- 718
- 1
- 4
- 8
-
This did not work. I edited the above and ran it, receiving "true" back for each user however all email preferences remain "checked" or enabled when I spot check in the portal. I ran this same code yesterday from your previous answer and found the same result. Are you sure this is for email preferences vs. notifications? (are notifications the pop-ups in the portal you see vs email notifications that actually are flooding my users with SoftLayer messages?) Specifically, I am looking to disable email preferences found in the portal under Accounts/Users/Email Preferences. – J.d. Jackson Aug 16 '18 at 12:23
-
I should also note that I see the correct format for Email Preferences using the SoftLayer_Email_Subscription class but in your example you reference SoftLayer_User_Customer::updateNotificationSubscriber. It would seem what I want is to work with the Email_Subscription class and the disable method vs what you posted here. – J.d. Jackson Aug 16 '18 at 12:46
-
Running the query to see what is enabled per user, looks correct. I see PLANNED_MAINT now set to 0, disabled yet I ran this yesterday and overnight more people received emails. Perhaps I misunderstand the difference between the notifications and email preferences and what I am trying to disable. The documentation leaves much to be desired around the SL API. – J.d. Jackson Aug 16 '18 at 13:13
-
To disable the email notices about unplanned events, planned maintenance, etc. to mass disable email notifications user by user that you post, the control portal use the method and service ¨SoftLayer_User_Customer::updateNotificationSubscriber¨ or the method ¨updateSubscriberDeliveryMethod¨ of the same service where you have to specify the “deliveryMethodKeyNames” in this case “Email”, it request you can see in the first link about examples the email notifications above. – F.Ojeda Aug 16 '18 at 15:12
-
For more references you can see these documentations: https://softlayer.github.io/reference/services/SoftLayer_User_Customer/updateNotificationSubscriber/, https://softlayer.github.io/reference/services/SoftLayer_User_Customer/updateSubscriberDeliveryMethod/ – F.Ojeda Aug 16 '18 at 15:15
-
If you just want to disable the email preferences options, it seems that you have to disable each user with their own credentials. You could see this information in the control portal: https://control.softlayer.com/account/user/email-preferences. You will not see differences o changes in the control portal/Account/Users/Email Preferences with the requests that I send you, you have to use other method and service. I will update the post above with a python script that you can use to disable or enable those options. – F.Ojeda Aug 16 '18 at 15:31
-
OK, thanks. That indeed worked for disabling the email options using the Email_Subscriber class and method disable, however is there a way to do this for all of my users? That class doesn't seem to accept a SL uid so I can't run this in a loop against my user id's. – J.d. Jackson Aug 17 '18 at 11:01
-
It is not possible to disable the email preferences for all the users of your account massively with this service because all the changes that you make in email preferences will not affect any other users on your account, you have to disable the email preferences user by user with their own credentials as mentioned above. – F.Ojeda Aug 17 '18 at 15:04