Skip to content

Instantly share code, notes, and snippets.

@scoopseven
Created October 3, 2019 16:49
Show Gist options
  • Save scoopseven/508547f1b3466f505a33b9e7079c8b2a to your computer and use it in GitHub Desktop.
Save scoopseven/508547f1b3466f505a33b9e7079c8b2a to your computer and use it in GitHub Desktop.
createsend PUT operation doesn't return any data; it's inconsistent with the POST operation that returns the email address as a measure of success. Problematic code: https://github.com/campaignmonitor/createsend-python/blob/ff6500cc3e23b14779c65dd3fed62d9b9aecdd38/lib/createsend/subscriber.py#L41
In [4]: success = subscriber.update(new_email_address='krista@ad.net',
...: name='%s %s' % ('krista@ad.net', 'krista@ad.net'),
...: custom_fields='',
...: resubscribe='false',
...: consent_to_track='yes')
# PUT request
/api/v3.2/subscribers/2a0b1fadb2c256efee33b5da93eee9ed.json?email=krista%40ad.net
# body
{"RestartSubscriptionBasedAutoresponders": false, "ConsentToTrack": "yes", "Name": "krista@ad.net krista@ad.net", "Resubscribe": "false", "EmailAddress": "krista@ad.net", "CustomFields": ""}
# headers
{'Content-Type': 'application/json; charset=utf-8', 'Accept-Encoding': 'gzip, deflate', 'Authorization': u'Basic UVcrdzJWRENMQm9LNjhhRVJlNFN1Um1aYSsxUHR1Z1FMZXh5b0FwbEd2QnFGQ1M1VmppbGRRK2lMQXFxWFk4V253NVdVS01XUGx3QlBLSk14MUhac0tHWDZ0Z3R0QVBjQzNRdTNQVUU1c0ZkY1JsTlRlK1V5bGxwU3ErdzdMOEtDYTB5c213dmJUUGhPUjlzMitWbkp3PT06eA==', 'User-Agent': 'createsend-python-6.0.0-2.7.14-Darwin-16.7.0-x86_64-i386-64bit'}
# PUT response
# response.msg
Date: Thu, 03 Oct 2019 16:42:04 GMT
Content-Length: 0
Connection: keep-alive
Cache-Control: private, s-maxage=0
P3p: CP="OTI DSP COR CUR IVD CONi OTPi OUR IND UNI STA PRE"
Server: cm-api-server
X-Cache: MISS
X-Edge-Request-Duration: 44ms
X-Edge-Request-Id: 57879ecb-5753-2825-2861-79f18a1820bf
X-Frame-Options: SAMEORIGIN
# response.status
200
# data
# RETURNS NOTHING
# ========================================= #
In [6]: success = add_subscriber.add(list_id=list_id,
...: email_address='marktest22@marktest.com',
...: name='Mark Kecko',
...: custom_fields='',
...: resubscribe='false',
...: consent_to_track='yes',
...: restart_subscription_based_autoresponders='True')
# POST request
/api/v3.2/subscribers/2a0b1fadb2c256efee33b5da93eee9ed.json
# body
{"RestartSubscriptionBasedAutoresponders": "True", "ConsentToTrack": "yes", "Name": "Mark Kecko", "Resubscribe": "false", "EmailAddress": "marktest22@marktest.com", "CustomFields": ""}
# headers
{'Content-Type': 'application/json; charset=utf-8', 'Accept-Encoding': 'gzip, deflate', 'Authorization': u'Basic UVcrdzJWRENMQm9LNjhhRVJlNFN1Um1aYSsxUHR1Z1FMZXh5b0FwbEd2QnFGQ1M1VmppbGRRK2lMQXFxWFk4V253NVdVS01XUGx3QlBLSk14MUhac0tHWDZ0Z3R0QVBjQzNRdTNQVUU1c0ZkY1JsTlRlK1V5bGxwU3ErdzdMOEtDYTB5c213dmJUUGhPUjlzMitWbkp3PT06eA==', 'User-Agent': 'createsend-python-6.0.0-2.7.14-Darwin-16.7.0-x86_64-i386-64bit'}
# POST response
# response.msg
Date: Thu, 03 Oct 2019 16:45:16 GMT
Content-Type: application/json
Content-Length: 25
Connection: keep-alive
Cache-Control: private, s-maxage=0
P3p: CP="OTI DSP COR CUR IVD CONi OTPi OUR IND UNI STA PRE"
Server: cm-api-server
X-Cache: MISS
X-Edge-Request-Duration: 35ms
X-Edge-Request-Id: c2e93c8f-0473-b484-a845-da363d19cb87
X-Frame-Options: SAMEORIGIN
# response.status
201
# data
"marktest22@marktest.com"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment