Skip to content

Commit 3c5f7b2

Browse files
authored
Merge pull request #90 from campaignmonitor/Add-SMS-Functionality
Add subscriber SMS functionality
2 parents f4f79ed + 19a7708 commit 3c5f7b2

3 files changed

Lines changed: 36 additions & 4 deletions

File tree

lib/createsend/subscriber.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def get(self, list_id=None, email_address=None, include_tracking_preference=Fals
2222
(list_id or self.list_id), params=params)
2323
return json_to_py(response)
2424

25-
def add(self, list_id, email_address, name, custom_fields, resubscribe, consent_to_track, restart_subscription_based_autoresponders=False):
25+
def add(self, list_id, email_address, name, custom_fields, resubscribe, consent_to_track, restart_subscription_based_autoresponders=False, mobile_number=False, consent_to_track_sms="Unchanged"):
2626
"""Adds a subscriber to a subscriber list."""
2727
validate_consent_to_track(consent_to_track)
2828
body = {
@@ -32,11 +32,17 @@ def add(self, list_id, email_address, name, custom_fields, resubscribe, consent_
3232
"Resubscribe": resubscribe,
3333
"ConsentToTrack": consent_to_track,
3434
"RestartSubscriptionBasedAutoresponders": restart_subscription_based_autoresponders}
35+
36+
if mobile_number:
37+
body["MobileNumber"] = mobile_number
38+
validate_consent_to_track(consent_to_track_sms)
39+
body["ConsentToSendSms"] = consent_to_track_sms
40+
3541
response = self._post("/subscribers/%s.json" %
3642
list_id, json.dumps(body))
3743
return json_to_py(response)
3844

39-
def update(self, new_email_address, name, custom_fields, resubscribe, consent_to_track, restart_subscription_based_autoresponders=False):
45+
def update(self, new_email_address, name, custom_fields, resubscribe, consent_to_track, restart_subscription_based_autoresponders=False, mobile_number=False, consent_to_track_sms="Unchanged"):
4046
"""Updates any aspect of a subscriber, including email address, name, and
4147
custom field data if supplied."""
4248
validate_consent_to_track(consent_to_track)
@@ -48,6 +54,12 @@ def update(self, new_email_address, name, custom_fields, resubscribe, consent_to
4854
"Resubscribe": resubscribe,
4955
"ConsentToTrack": consent_to_track,
5056
"RestartSubscriptionBasedAutoresponders": restart_subscription_based_autoresponders}
57+
58+
if mobile_number:
59+
body["MobileNumber"] = mobile_number
60+
validate_consent_to_track(consent_to_track_sms)
61+
body["ConsentToSendSms"] = consent_to_track_sms
62+
5163
response = self._put("/subscribers/%s.json" % self.list_id,
5264
body=json.dumps(body), params=params)
5365
# Update self.email_address, so this object can continue to be used
@@ -93,4 +105,4 @@ def delete(self):
93105
"""Moves this subscriber to the deleted state in the associated list."""
94106
params = {"email": self.email_address}
95107
response = self._delete("/subscribers/%s.json" %
96-
self.list_id, params=params)
108+
self.list_id, params=params)

samples/subscribers.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,29 @@
66
listId = 'YOUR_LIST_ID'
77
emailAddress = 'YOUR_SUBSCRIBER_EMAIL_ADDRESS'
88

9+
subscriberName = "YOUR_SUBSCRIBER_NAME"
10+
subscriberCustomFields = []
11+
subscriberResubscribed = False
12+
subscriberConsentToTrack = 'Unchanged'
13+
subscriberMobileNumber = "+61491570006" # This is a reserved mobile number by the Australian Communications and Media Authority
14+
subscriberConsentToSendSms = "Yes"
15+
916
subscriber = Subscriber(auth, listId, emailAddress)
1017

1118
# Get the details for a subscriber
1219
subscriberDetail = subscriber.get()
1320
for property, value in vars(subscriberDetail).items():
1421
print(property, ":", value)
22+
23+
# Adding a subscriber
24+
#This implemntation defaults the value of 'restart_subscription_based_autoresponders' to false
25+
subscriber.add(listId, emailAddress, subscriberName, subscriberCustomFields, subscriberResubscribed, subscriberConsentToTrack)
26+
27+
# Adding a subscriber with a mobile number
28+
#This implemntation defaults the value of 'restart_subscription_based_autoresponders' to false
29+
#This also sets the default value of 'consent_to_track_sms' to 'unchanged', meaning new users will not receive SMS communications by default."
30+
subscriber.add(listId, emailAddress, subscriberName, subscriberCustomFields, subscriberConsentToTrack, mobile_Number=subscriberMobileNumber)
31+
32+
#Alternative to set SMS tracking permissions
33+
# This implemntation defaults the value of 'restart_subscription_based_autoresponders' to false
34+
subscriber.add(listId, emailAddress, subscriberName, subscriberCustomFields, subscriberConsentToTrack, mobile_Number=subscriberMobileNumber, consent_to_track_sms=subscriberConsentToSendSms)

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
setup(
44
name="createsend",
5-
version='9.0.2',
5+
version='9.1.2',
66
description="A library which implements the complete functionality of the Campaign Monitor API.",
77
author='Campaign Monitor',
88
author_email='support@campaignmonitor.com',

0 commit comments

Comments
 (0)