Skip to content

Commit

Permalink
Add SMS Fields to subscriber.py
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexisT-CM committed Jan 22, 2025
1 parent 39fcf75 commit 94f08b2
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions lib/createsend/subscriber.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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)
Expand All @@ -48,6 +53,12 @@ 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
Expand Down Expand Up @@ -93,4 +104,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)

0 comments on commit 94f08b2

Please sign in to comment.