From 923205df2332af651158950a2a6cbfa33c19a046 Mon Sep 17 00:00:00 2001 From: AlexisT-CM Date: Fri, 24 Jan 2025 09:33:27 +1100 Subject: [PATCH 1/3] Add SMS parameters to add() and update() --- lib/createsend/subscriber.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/createsend/subscriber.py b/lib/createsend/subscriber.py index 2be9e6d..ed2e0f1 100644 --- a/lib/createsend/subscriber.py +++ b/lib/createsend/subscriber.py @@ -22,7 +22,7 @@ def get(self, list_id=None, email_address=None, include_tracking_preference=Fals (list_id or self.list_id), params=params) return json_to_py(response) - def add(self, list_id, email_address, name, custom_fields, resubscribe, consent_to_track, restart_subscription_based_autoresponders=False): + 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"): """Adds a subscriber to a subscriber list.""" validate_consent_to_track(consent_to_track) body = { @@ -32,11 +32,16 @@ def add(self, list_id, email_address, name, custom_fields, resubscribe, consent_ "Resubscribe": resubscribe, "ConsentToTrack": consent_to_track, "RestartSubscriptionBasedAutoresponders": restart_subscription_based_autoresponders} + + if mobile_number: + body["MobileNumber"] = mobile_number + body["ConsentToSendSms"] = consent_to_track_sms + response = self._post("/subscribers/%s.json" % list_id, json.dumps(body)) return json_to_py(response) - def update(self, new_email_address, name, custom_fields, resubscribe, consent_to_track, restart_subscription_based_autoresponders=False): + 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"): """Updates any aspect of a subscriber, including email address, name, and custom field data if supplied.""" validate_consent_to_track(consent_to_track) @@ -48,6 +53,11 @@ def update(self, new_email_address, name, custom_fields, resubscribe, consent_to "Resubscribe": resubscribe, "ConsentToTrack": consent_to_track, "RestartSubscriptionBasedAutoresponders": restart_subscription_based_autoresponders} + + if mobile_number: + body["MobileNumber"] = mobile_number + body["ConsentToSendSms"] = consent_to_track_sms + response = self._put("/subscribers/%s.json" % self.list_id, body=json.dumps(body), params=params) # Update self.email_address, so this object can continue to be used @@ -93,4 +103,4 @@ def delete(self): """Moves this subscriber to the deleted state in the associated list.""" params = {"email": self.email_address} response = self._delete("/subscribers/%s.json" % - self.list_id, params=params) + self.list_id, params=params) \ No newline at end of file From fb0a64cc5ebd47b0b206980b6c454691188429c4 Mon Sep 17 00:00:00 2001 From: AlexisT-CM Date: Fri, 24 Jan 2025 09:33:40 +1100 Subject: [PATCH 2/3] Update subscribes.py --- samples/subscribers.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/samples/subscribers.py b/samples/subscribers.py index 031a5a1..e68c41a 100644 --- a/samples/subscribers.py +++ b/samples/subscribers.py @@ -6,9 +6,29 @@ listId = 'YOUR_LIST_ID' emailAddress = 'YOUR_SUBSCRIBER_EMAIL_ADDRESS' +subscriberName = "YOUR_SUBSCRIBER_NAME" +subscriberCustomFields = [] +subscriberResubscribed = False +subscriberConsentToTrack = 'Unchanged' +subscriberMobileNumber = "+61491570006" # This is a reserved mobile number by the Australian Communications and Media Authority +subscriberConsentToSendSms = "Yes" + subscriber = Subscriber(auth, listId, emailAddress) # Get the details for a subscriber subscriberDetail = subscriber.get() for property, value in vars(subscriberDetail).items(): print(property, ":", value) + +# Adding a subscriber + #This implemntation defaults the value of 'restart_subscription_based_autoresponders' to false +subscriber.add(listId, emailAddress, subscriberName, subscriberCustomFields, subscriberResubscribed, subscriberConsentToTrack) + +# Adding a subscriber with a mobile number + #This implemntation defaults the value of 'restart_subscription_based_autoresponders' to false + #This also sets the default value of 'consent_to_track_sms' to 'unchanged', meaning new users will not receive SMS communications by default." +subscriber.add(listId, emailAddress, subscriberName, subscriberCustomFields, subscriberConsentToTrack, mobile_Number=subscriberMobileNumber) + +#Alternative to set SMS tracking permissions + # This implemntation defaults the value of 'restart_subscription_based_autoresponders' to false +subscriber.add(listId, emailAddress, subscriberName, subscriberCustomFields, subscriberConsentToTrack, mobile_Number=subscriberMobileNumber, consent_to_track_sms=subscriberConsentToSendSms) \ No newline at end of file From 19a770859098213ce9e0a24d532255b05040c79f Mon Sep 17 00:00:00 2001 From: AlexisT-CM Date: Wed, 29 Jan 2025 13:34:18 +1100 Subject: [PATCH 3/3] Version 9.1.2 --- lib/createsend/subscriber.py | 2 ++ setup.py | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/createsend/subscriber.py b/lib/createsend/subscriber.py index ed2e0f1..9d30e81 100644 --- a/lib/createsend/subscriber.py +++ b/lib/createsend/subscriber.py @@ -35,6 +35,7 @@ def add(self, list_id, email_address, name, custom_fields, resubscribe, consent_ if mobile_number: body["MobileNumber"] = mobile_number + validate_consent_to_track(consent_to_track_sms) body["ConsentToSendSms"] = consent_to_track_sms response = self._post("/subscribers/%s.json" % @@ -56,6 +57,7 @@ def update(self, new_email_address, name, custom_fields, resubscribe, consent_to if mobile_number: body["MobileNumber"] = mobile_number + validate_consent_to_track(consent_to_track_sms) body["ConsentToSendSms"] = consent_to_track_sms response = self._put("/subscribers/%s.json" % self.list_id, diff --git a/setup.py b/setup.py index 27760a8..c754adb 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ setup( name="createsend", - version='9.0.2', + version='9.1.2', description="A library which implements the complete functionality of the Campaign Monitor API.", author='Campaign Monitor', author_email='support@campaignmonitor.com',