async def create(self, store_id, data): """ Add a new customer to a store. :param store_id: The store id. :type store_id: :py:class:`str` :param data: The request body parameters :type data: :py:class:`dict` data = { "id": string*, "email_address": string*, "opt_in_status": boolean* } """ self.store_id = store_id if 'id' not in data: raise KeyError('The store customer must have an id') if 'email_address' not in data: raise KeyError('The store customer must have an email_address') check_email(data['email_address']) if 'opt_in_status' not in data: raise KeyError('The store customer must have an opt_in_status') if data['opt_in_status'] not in [True, False]: raise TypeError('The opt_in_status must be True or False') response = await self._mc_client._post(url=self._build_path(store_id, 'customers'), data=data) if response is not None: self.customer_id = response['id'] else: self.customer_id = None return response
def update(self, campaign_id, data): """ Update some or all of the settings for a specific campaign. :param campaign_id: The unique id for the campaign. :type campaign_id: :py:class:`str` :param data: The request body parameters :type data: :py:class:`dict` data = { "settings": object* { "subject_line": string*, "from_name": string*, "reply_to": string* }, } """ self.campaign_id = campaign_id if 'settings' not in data: raise KeyError('The campaign must have settings') if 'subject_line' not in data['settings']: raise KeyError('The campaign settings must have a subject_line') if 'from_name' not in data['settings']: raise KeyError('The campaign settings must have a from_name') if 'reply_to' not in data['settings']: raise KeyError('The campaign settings must have a reply_to') check_email(data['settings']['reply_to']) return self._mc_client._patch(url=self._build_path(campaign_id), data=data)
async def create(self, workflow_id, email_id, data): """ Manually add a subscriber to a workflow, bypassing the default trigger settings. You can also use this endpoint to trigger a series of automated emails in an API 3.0 workflow type or add subscribers to an automated email queue that uses the API request delay type. :param workflow_id: The unique id for the Automation workflow. :type workflow_id: :py:class:`str` :param email_id: The unique id for the Automation workflow email. :type email_id: :py:class:`str` :param data: The request body parameters :type data: :py:class:`dict` data = { "email_address": string* } """ self.workflow_id = workflow_id self.email_id = email_id if 'email_address' not in data: raise KeyError( 'The automation email queue must have an email_address') check_email(data['email_address']) response = await self._mc_client._post(url=self._build_path( workflow_id, 'emails', email_id, 'queue'), data=data) if response is not None: self.subscriber_hash = response['id'] else: self.subscriber_hash = None return response
async def create_or_update(self, store_id, customer_id, data): """ Add or update a customer. :param store_id: The store id. :type store_id: :py:class:`str` :param customer_id: The id for the customer of a store. :type customer_id: :py:class:`str` :param data: The request body parameters :type data: :py:class:`dict` data = { "id": string*, "email_address": string*, "opt_in_status": boolean } """ self.store_id = store_id self.customer_id = customer_id if 'id' not in data: raise KeyError('The store customer must have an id') if 'email_address' not in data: raise KeyError('Each store customer must have an email_address') check_email(data['email_address']) if 'opt_in_status' not in data: raise KeyError('The store customer must have an opt_in_status') if data['opt_in_status'] not in [True, False]: raise TypeError('The opt_in_status must be True or False') return await self._mc_client._put(url=self._build_path(store_id, 'customers', customer_id), data=data)
def create(self, workflow_id, email_id, data): """ Manually add a subscriber to a workflow, bypassing the default trigger settings. You can also use this endpoint to trigger a series of automated emails in an API 3.0 workflow type or add subscribers to an automated email queue that uses the API request delay type. :param workflow_id: The unique id for the Automation workflow. :type workflow_id: :py:class:`str` :param email_id: The unique id for the Automation workflow email. :type email_id: :py:class:`str` :param data: The request body parameters :type data: :py:class:`dict` data = { "email_address": string* } """ self.workflow_id = workflow_id self.email_id = email_id try: test = data['email_address'] except KeyError as error: new_msg = 'The automation email queue must have an email_address, {}'.format( error) six.reraise(KeyError, KeyError(new_msg), sys.exc_info()[2]) check_email(data['email_address']) response = self._mc_client._post(url=self._build_path( workflow_id, 'emails', email_id, 'actions/pause-all-emails'), data=data) if response is not None: self.subscriber_hash = response['id'] else: self.subscriber_hash = None return response
def create(self, conversation_id, data): """ Post a new message to a conversation. :param conversation_id: The unique id for the conversation. :type conversation_id: :py:class:`str` :param data: The request body parameters :type data: :py:class:`dict` data = { "from_email": string*, "read": boolean* } """ self.conversation_id = conversation_id try: test = data['from_email'] except KeyError as error: error.message += ' The conversation message must have a from_email' raise check_email(data['from_email']) try: test = data['read'] except KeyError as error: error.message += ' The conversation message must have a read' raise if data['read'] not in [True, False]: raise TypeError('The conversation message read must be True or False') response = self._mc_client._post(url=self._build_path(conversation_id, 'messages'), data=data) self.message_id = response['id'] return response
async def create(self, list_id, data): """ Add a new member to the list. :param list_id: The unique id for the list. :type list_id: :py:class:`str` :param data: The request body parameters :type data: :py:class:`dict` data = { "status": string*, (Must be one of 'subscribed', 'unsubscribed', 'cleaned', 'pending', or 'transactional') "email_address": string* } """ self.list_id = list_id if 'status' not in data: raise KeyError('The list member must have a status') if data['status'] not in [ 'subscribed', 'unsubscribed', 'cleaned', 'pending', 'transactional' ]: raise ValueError( 'The list member status must be one of "subscribed", "unsubscribed", "cleaned", ' '"pending", or "transactional"') if 'email_address' not in data: raise KeyError('The list member must have an email_address') check_email(data['email_address']) response = await self._mc_client._post(url=self._build_path( list_id, 'members'), data=data) if response is not None: self.subscriber_hash = response['id'] else: self.subscriber_hash = None return response
def create(self, workflow_id, data): """ Remove a subscriber from a specific Automation workflow. You can remove a subscriber at any point in an Automation workflow, regardless of how many emails they’ve been sent from that workflow. Once they’re removed, they can never be added back to the same workflow. :param workflow_id: The unique id for the Automation workflow. :type workflow_id: :py:class:`str` :param data: The request body parameters :type data: :py:class:`dict` data = { "email_address": string* } """ self.workflow_id = workflow_id try: test = data['email_address'] except KeyError as error: new_msg = 'The automation removed subscriber must have an email_address, {}'.format( error) six.reraise(KeyError, KeyError(new_msg), sys.exc_info()[2]) check_email(data['email_address']) return self._mc_client._post(url=self._build_path( workflow_id, 'removed-subscribers'), data=data)
def create_or_update(self, store_id, customer_id, data): """ Add or update a customer. :param store_id: The store id. :type store_id: :py:class:`str` :param customer_id: The id for the customer of a store. :type customer_id: :py:class:`str` :param data: The request body parameters :type data: :py:class:`dict` data = { "id": string*, "email_address": string*, "opt_in_status": boolean } """ self.store_id = store_id self.customer_id = customer_id if 'id' not in data: raise KeyError('The store customer must have an id') if 'email_address' not in data: raise KeyError('Each store customer must have an email_address') check_email(data['email_address']) if 'opt_in_status' not in data: raise KeyError('The store customer must have an opt_in_status') if data['opt_in_status'] not in [True, False]: raise TypeError('The opt_in_status must be True or False') return self._mc_client._put(url=self._build_path(store_id, 'customers', customer_id), data=data)
def create(self, store_id, data): """ Add a new customer to a store. :param store_id: The store id. :type store_id: :py:class:`str` :param data: The request body parameters :type data: :py:class:`dict` data = { "id": string*, "email_address": string*, "opt_in_status": boolean* } """ self.store_id = store_id if 'id' not in data: raise KeyError('The store customer must have an id') if 'email_address' not in data: raise KeyError('The store customer must have an email_address') check_email(data['email_address']) if 'opt_in_status' not in data: raise KeyError('The store customer must have an opt_in_status') if data['opt_in_status'] not in [True, False]: raise TypeError('The opt_in_status must be True or False') response = self._mc_client._post(url=self._build_path(store_id, 'customers'), data=data) if response is not None: self.customer_id = response['id'] else: self.customer_id = None return response
def create(self, list_id, data): """ Add a new member to the list. :param list_id: The unique id for the list. :type list_id: :py:class:`str` :param data: The request body parameters :type data: :py:class:`dict` data = { "status": string*, (Must be one of 'subscribed', 'unsubscribed', 'cleaned', or 'pending') "email_address": string* } """ self.list_id = list_id if 'status' not in data: raise KeyError('The list member must have a status') if data['status'] not in ['subscribed', 'unsubscribed', 'cleaned', 'pending']: raise ValueError('The list member status must be one of "subscribed", "unsubscribed", "cleaned", or ' '"pending"') if 'email_address' not in data: raise KeyError('The list member must have an email_address') check_email(data['email_address']) response = self._mc_client._post(url=self._build_path(list_id, 'members'), data=data) if response is not None: self.subscriber_hash = response['id'] else: self.subscriber_hash = None return response
def create_or_update(self, list_id, subscriber_hash, data): """ Add or update a list member. :param list_id: The unique id for the list. :type list_id: :py:class:`str` :param subscriber_hash: The MD5 hash of the lowercase version of the list member’s email address. :type subscriber_hash: :py:class:`str` :param data: The request body parameters :type data: :py:class:`dict` data = { "email_address": string*, "status_if_new": string* (Must be one of 'subscribed', 'unsubscribed', 'cleaned' or 'pending') } """ subscriber_hash = check_subscriber_hash(subscriber_hash) self.list_id = list_id self.subscriber_hash = subscriber_hash if 'email_address' not in data: raise KeyError('The list member must have an email_address') check_email(data['email_address']) if 'status_if_new' not in data: raise KeyError('The list member must have a status_if_new') if data['status_if_new'] not in ['subscribed', 'unsubscribed', 'cleaned', 'pending']: raise ValueError('The list member status_if_new must be one of "subscribed", "unsubscribed", "cleaned", ' 'or "pending"') return self._mc_client._put(url=self._build_path(list_id, 'members', subscriber_hash), data=data)
def create(self, conversation_id, data): """ Post a new message to a conversation. :param conversation_id: The unique id for the conversation. :type conversation_id: :py:class:`str` :param data: The request body parameters :type data: :py:class:`dict` data = { "from_email": string*, "read": boolean* } """ self.conversation_id = conversation_id if 'from_email' not in data: raise KeyError('The conversation message must have a from_email') check_email(data['from_email']) if 'read' not in data: raise KeyError('The conversation message must have a read') if data['read'] not in [True, False]: raise TypeError('The conversation message read must be True or False') response = self._mc_client._post(url=self._build_path(conversation_id, 'messages'), data=data) if response is not None: self.message_id = response['id'] else: self.message_id = None return response
async def create_or_update(self, list_id, subscriber_hash, data): """ Add or update a list member. :param list_id: The unique id for the list. :type list_id: :py:class:`str` :param subscriber_hash: The MD5 hash of the lowercase version of the list member’s email address. :type subscriber_hash: :py:class:`str` :param data: The request body parameters :type data: :py:class:`dict` data = { "email_address": string*, "status_if_new": string* (Must be one of 'subscribed', 'unsubscribed', 'cleaned', 'pending', or 'transactional') } """ subscriber_hash = check_subscriber_hash(subscriber_hash) self.list_id = list_id self.subscriber_hash = subscriber_hash if 'email_address' not in data: raise KeyError('The list member must have an email_address') check_email(data['email_address']) if 'status_if_new' not in data: raise KeyError('The list member must have a status_if_new') if data['status_if_new'] not in [ 'subscribed', 'unsubscribed', 'cleaned', 'pending', 'transactional' ]: raise ValueError( 'The list member status_if_new must be one of "subscribed", "unsubscribed", "cleaned", ' '"pending", or "transactional"') return await self._mc_client._put(url=self._build_path( list_id, 'members', subscriber_hash), data=data)
def create(self, workflow_id, email_id, data): """ Manually add a subscriber to a workflow, bypassing the default trigger settings. You can also use this endpoint to trigger a series of automated emails in an API 3.0 workflow type or add subscribers to an automated email queue that uses the API request delay type. :param workflow_id: The unique id for the Automation workflow. :type workflow_id: :py:class:`str` :param email_id: The unique id for the Automation workflow email. :type email_id: :py:class:`str` :param data: The request body parameters :type data: :py:class:`dict` data = { "email_address": string* } """ self.workflow_id = workflow_id self.email_id = email_id if "email_address" not in data: raise KeyError("The automation email queue must have an email_address") check_email(data["email_address"]) response = self._mc_client._post( url=self._build_path(workflow_id, "emails", email_id, "actions/pause-all-emails"), data=data ) if response is not None: self.subscriber_hash = response["id"] else: self.subscriber_hash = None return response
def create(self, workflow_id, email_id, data): """ Manually add a subscriber to a workflow, bypassing the default trigger settings. You can also use this endpoint to trigger a series of automated emails in an API 3.0 workflow type or add subscribers to an automated email queue that uses the API request delay type. :param workflow_id: The unique id for the Automation workflow. :type workflow_id: :py:class:`str` :param email_id: The unique id for the Automation workflow email. :type email_id: :py:class:`str` :param data: The request body parameters :type data: :py:class:`dict` data = { "email_address": string* } """ self.workflow_id = workflow_id self.email_id = email_id try: test = data['email_address'] except KeyError as error: error.message += ' The automation email queue must have an email_address' raise check_email(data['email_address']) response = self._mc_client._post( url=self._build_path(workflow_id, 'emails', email_id, 'actions/pause-all-emails'), data=data ) self.subscriber_hash = response['id'] return response
def update_members(self, list_id, data): """ Batch subscribe or unsubscribe list members. Only the members array is required in the request body parameters. Within the members array, each member requires an email_address and either a status or status_if_new. The update_existing parameter will also be considered required to help prevent accidental updates to existing members and will default to false if not present. :param list_id: The unique id for the list. :type list_id: :py:class:`str` :param data: The request body parameters :type data: :py:class:`dict` data = { "members": array* [ { "email_address": string*, "status": string* (Must be one of 'subscribed', 'unsubscribed', 'cleaned', or 'pending'), "status_if_new": string* (Must be one of 'subscribed', 'unsubscribed', 'cleaned', or 'pending') } ], "update_existing": boolean* } """ self.list_id = list_id if 'members' not in data: raise KeyError('The update must have at least one member') else: if not len(data['members']) <= 500: raise ValueError( 'You may only batch sub/unsub 500 members at a time') for member in data['members']: if 'email_address' not in member: raise KeyError('Each list member must have an email_address') check_email(member['email_address']) if 'status' not in member and 'status_if_new' not in member: raise KeyError( 'Each list member must have either a status or a status_if_new' ) valid_statuses = [ 'subscribed', 'unsubscribed', 'cleaned', 'pending' ] if 'status' in member and member['status'] not in valid_statuses: raise ValueError( 'The list member status must be one of "subscribed", "unsubscribed", "cleaned", or ' '"pending"') if 'status_if_new' in member and member[ 'status_if_new'] not in valid_statuses: raise ValueError( 'The list member status_if_new must be one of "subscribed", "unsubscribed", ' '"cleaned", or "pending"') if 'update_existing' not in data: data['update_existing'] = False return self._mc_client._post(url=self._build_path(list_id), data=data)
def update_members(self, list_id, data): """ Batch subscribe or unsubscribe list members. Only the members array is required in the request body parameters, but the description of it mentions both the email_address and status values, so those are going to be treated as required. The update_existing parameter will also be considered required to help prevent accidental updates to existing members and will default to false if not present. :param list_id: The unique id for the list. :type list_id: :py:class:`str` :param data: The request body parameters :type data: :py:class:`dict` data = { "members": array* [ { "email_address": string*, "status": string* (Must be one of 'subscribed', 'unsubscribed', 'cleaned', or 'pending') } ], "update_existing": boolean* } """ self.list_id = list_id try: test = data['members'] if not len(test) <= 500: raise ValueError('You may only batch sub/unsub 500 members at a time') except KeyError as error: error.message += ' The update must have at least one member' raise for member in data['members']: try: test = member['email_address'] except KeyError as error: error.message += ' Each list member must have an email_address' raise check_email(member['email_address']) try: test = member['status'] except KeyError as error: error.message += ' Each list member must have a status' raise if member['status'] not in ['subscribed', 'unsubscribed', 'cleaned', 'pending']: raise ValueError('The list member status must be one of "subscribed", "unsubscribed", "cleaned", or ' '"pending"') try: test = data['update_existing'] except KeyError: data['update_existing'] = False return self._mc_client._post(url=self._build_path(), data=data)
def create(self, list_id, segment_id, data): """ Add a member to a static segment. The documentation does not currently elaborate on the path or request body parameters. Looking at the example provided, it will be assumed that email_address and status are required request body parameters and they are documented and error-checked as such. :param list_id: The unique id for the list. :type list_id: :py:class:`str` :param segment_id: The unique id for the segment. :type segment_id: :py:class:`str` :param data: The request body parameters :type data: :py:class:`dict` data = { "email_address": string*, "status": string* (Must be one of 'subscribed', 'unsubscribed', 'cleaned', or 'pending') } """ self.list_id = list_id self.segment_id = segment_id try: test = data['email_address'] except KeyError as error: new_msg = 'The list segment member must have an email_address, {}'.format( error) six.reraise(KeyError, KeyError(new_msg), sys.exc_info()[2]) check_email(data['email_address']) try: test = data['status'] except KeyError as error: new_msg = 'The list segment member must have a status, {}'.format( error) six.reraise(KeyError, KeyError(new_msg), sys.exc_info()[2]) if data['status'] not in [ 'subscribed', 'unsubscribed', 'cleaned', 'pending' ]: raise ValueError( 'The list segment member status must be one of "subscribed", "unsubscribed", "cleaned" or' '"pending"') response = self._mc_client._post(url=self._build_path( list_id, 'segments', segment_id, 'members'), data=data) if response is not None: self.subscriber_hash = response['id'] else: self.subscriber_hash = None return response
def update_members(self, list_id, data): """ Batch subscribe or unsubscribe list members. Only the members array is required in the request body parameters. Within the members array, each member requires an email_address and either a status or status_if_new. The update_existing parameter will also be considered required to help prevent accidental updates to existing members and will default to false if not present. :param list_id: The unique id for the list. :type list_id: :py:class:`str` :param data: The request body parameters :type data: :py:class:`dict` data = { "members": array* [ { "email_address": string*, "status": string* (Must be one of 'subscribed', 'unsubscribed', 'cleaned', or 'pending'), "status_if_new": string* (Must be one of 'subscribed', 'unsubscribed', 'cleaned', or 'pending') } ], "update_existing": boolean* } """ self.list_id = list_id if 'members' not in data: raise KeyError('The update must have at least one member') else: if not len(data['members']) <= 500: raise ValueError('You may only batch sub/unsub 500 members at a time') for member in data['members']: if 'email_address' not in member: raise KeyError('Each list member must have an email_address') check_email(member['email_address']) if 'status' not in member and 'status_if_new' not in member: raise KeyError('Each list member must have either a status or a status_if_new') valid_statuses = ['subscribed', 'unsubscribed', 'cleaned', 'pending'] if 'status' in member and member['status'] not in valid_statuses: raise ValueError('The list member status must be one of "subscribed", "unsubscribed", "cleaned", or ' '"pending"') if 'status_if_new' in member and member['status_if_new'] not in valid_statuses: raise ValueError('The list member status_if_new must be one of "subscribed", "unsubscribed", ' '"cleaned", or "pending"') if 'update_existing' not in data: data['update_existing'] = False return self._mc_client._post(url=self._build_path(list_id), data=data)
def is_valid_email(email: Text) -> bool: """Use mailchimp3 helper function to validate that it will accept it as a valid email""" try: email = str(email) check_email(email) return True except ValueError: # purposely raised in case of invalid email return False except Exception as e: logger.warning( f"Error: exception in check_email.\n" f"{type(e)} - {e}\n" f"email = {email}\n" f"type(email) = {type(email)}" ) return False
def update(self, campaign_id, data): """ Update some or all of the settings for a specific campaign. :param campaign_id: The unique id for the campaign. :type campaign_id: :py:class:`str` :param data: The request body parameters :type data: :py:class:`dict` data = { "settings": object* { "subject_line": string*, "from_name": string*, "reply_to": string* }, } """ self.campaign_id = campaign_id try: test = data['settings'] except KeyError as error: new_msg = 'The campaign must have settings, {}'.format(error) six.reraise(KeyError, KeyError(new_msg), sys.exc_info()[2]) try: test = data['settings']['subject_line'] except KeyError as error: new_msg = 'The campaign settings must have a subject_line, {}'.format( error) six.reraise(KeyError, KeyError(new_msg), sys.exc_info()[2]) try: test = data['settings']['from_name'] except KeyError as error: new_msg = 'The campaign settings must have a from_name, {}'.format( error) six.reraise(KeyError, KeyError(new_msg), sys.exc_info()[2]) try: test = data['settings']['reply_to'] except KeyError as error: new_msg = 'The campaign settings must have a reply_to, {}'.format( error) six.reraise(KeyError, KeyError(new_msg), sys.exc_info()[2]) check_email(data['settings']['reply_to']) return self._mc_client._patch(url=self._build_path(campaign_id), data=data)
def test(self, campaign_id, data): """ Send a test email. :param campaign_id: The unique id for the campaign. :type campaign_id: :py:class:`str` :param data: The request body parameters :type data: :py:class:`dict` data = { "test_emails": array*, "send_type": string* (Must be one of "html" or "plain_text") } """ for email in data['test_emails']: check_email(email) if data['send_type'] not in ['html', 'plain_text']: raise ValueError('The send_type must be either "html" or "plain_text"') self.campaign_id = campaign_id return self._mc_client._post(url=self._build_path(campaign_id, 'actions/test'), data=data)
def create(self, workflow_id, data): """ Remove a subscriber from a specific Automation workflow. You can remove a subscriber at any point in an Automation workflow, regardless of how many emails they’ve been sent from that workflow. Once they’re removed, they can never be added back to the same workflow. :param workflow_id: The unique id for the Automation workflow. :type workflow_id: :py:class:`str` :param data: The request body parameters :type data: :py:class:`dict` data = { "email_address": string* } """ self.workflow_id = workflow_id if 'email_address' not in data: raise KeyError('The automation removed subscriber must have an email_address') check_email(data['email_address']) return self._mc_client._post(url=self._build_path(workflow_id, 'removed-subscribers'), data=data)
def create_or_update(self, list_id, subscriber_hash, data): """ Add or update a list member. :param list_id: The unique id for the list. :type list_id: :py:class:`str` :param subscriber_hash: The MD5 hash of the lowercase version of the list member’s email address. :type subscriber_hash: :py:class:`str` :param data: The request body parameters :type data: :py:class:`dict` data = { "email_address": string*, "status_if_new": string* (Must be one of 'subscribed', 'unsubscribed', 'cleaned' or 'pending') } """ subscriber_hash = check_subscriber_hash(subscriber_hash) self.list_id = list_id self.subscriber_hash = subscriber_hash try: test = data['email_address'] except KeyError as error: new_msg = 'The list member must have an email_address, {}'.format( error) six.reraise(KeyError, KeyError(new_msg), sys.exc_info()[2]) check_email(data['email_address']) try: test = data['status_if_new'] except KeyError as error: new_msg = 'The list member must have a status_if_new, {}'.format( error) six.reraise(KeyError, KeyError(new_msg), sys.exc_info()[2]) if data['status_if_new'] not in [ 'subscribed', 'unsubscribed', 'cleaned', 'pending' ]: raise ValueError( 'The list member status_if_new must be one of "subscribed", "unsubscribed", "cleaned", ' 'or "pending"') return self._mc_client._put(url=self._build_path( list_id, 'members', subscriber_hash), data=data)
def create(self, list_id, data): """ Add a new member to the list. :param list_id: The unique id for the list. :type list_id: :py:class:`str` :param data: The request body parameters :type data: :py:class:`dict` data = { "status": string*, (Must be one of 'subscribed', 'unsubscribed', 'cleaned', or 'pending') "email_address": string* } """ self.list_id = list_id try: test = data['status'] except KeyError as error: new_msg = 'The list member must have a status, {}'.format(error) six.reraise(KeyError, KeyError(new_msg), sys.exc_info()[2]) if data['status'] not in [ 'subscribed', 'unsubscribed', 'cleaned', 'pending' ]: raise ValueError( 'The list member status must be one of "subscribed", "unsubscribed", "cleaned", or ' '"pending"') try: test = data['email_address'] except KeyError as error: new_msg = 'The list member must have an email_address, {}'.format( error) six.reraise(KeyError, KeyError(new_msg), sys.exc_info()[2]) check_email(data['email_address']) response = self._mc_client._post(url=self._build_path( list_id, 'members'), data=data) if response is not None: self.subscriber_hash = response['id'] else: self.subscriber_hash = None return response
def create(self, list_id, segment_id, data): """ Add a member to a static segment. The documentation does not currently elaborate on the path or request body parameters. Looking at the example provided, it will be assumed that email_address and status are required request body parameters and they are documented and error-checked as such. :param list_id: The unique id for the list. :type list_id: :py:class:`str` :param segment_id: The unique id for the segment. :type segment_id: :py:class:`str` :param data: The request body parameters :type data: :py:class:`dict` data = { "email_address": string*, "status": string* (Must be one of 'subscribed', 'unsubscribed', 'cleaned', or 'pending') } """ self.list_id = list_id self.segment_id = segment_id try: test = data['email_address'] except KeyError as error: error.message += ' The list segment member must have an email_address' raise check_email(data['email_address']) try: test = data['status'] except KeyError as error: error.message += ' The list segment member must have a status' raise if data['status'] not in ['subscribed', 'unsubscribed', 'cleaned', 'pending']: raise ValueError('The list segment member status must be one of "subscribed", "unsubscribed", "cleaned" or' '"pending"') response = self._mc_client._post(url=self._build_path(list_id, 'segments', segment_id, 'members'), data=data) self.subscriber_hash = response['id'] return response
def test(self, campaign_id, data): """ Send a test email. :param campaign_id: The unique id for the campaign. :type campaign_id: :py:class:`str` :param data: The request body parameters :type data: :py:class:`dict` data = { "test_emails": array*, "send_type": string* (Must be one of "html" or "plaintext") } """ for email in data['test_emails']: check_email(email) if data['send_type'] not in ['html', 'plaintext']: raise ValueError( 'The send_type must be either "html" or "plaintext"') self.campaign_id = campaign_id return self._mc_client._post(url=self._build_path( campaign_id, 'actions/test'), data=data)
def create(self, store_id, data): """ Add a new customer to a store. :param store_id: The store id. :type store_id: :py:class:`str` :param data: The request body parameters :type data: :py:class:`dict` data = { "id": string*, "email_address": string*, "opt_in_status": boolean* } """ self.store_id = store_id try: test = data['id'] except KeyError as error: new_msg = 'The store customer must have an id, {}'.format(error) six.reraise(KeyError, KeyError(new_msg), sys.exc_info()[2]) try: test = data['email_address'] except KeyError as error: new_msg = 'The store customer must have an email_address, {}'.format(error) six.reraise(KeyError, KeyError(new_msg), sys.exc_info()[2]) check_email(data['email_address']) try: test = data['opt_in_status'] except KeyError as error: new_msg = 'The store customer must have an opt_in_status, {}'.format(error) six.reraise(KeyError, KeyError(new_msg), sys.exc_info()[2]) if data['opt_in_status'] not in [True, False]: raise TypeError('The opt_in_status must be True or False') response = self._mc_client._post(url=self._build_path(store_id, 'customers'), data=data) if response is not None: self.customer_id = response['id'] else: self.customer_id = None return response
def create(self, conversation_id, data): """ Post a new message to a conversation. :param conversation_id: The unique id for the conversation. :type conversation_id: :py:class:`str` :param data: The request body parameters :type data: :py:class:`dict` data = { "from_email": string*, "read": boolean* } """ self.conversation_id = conversation_id try: test = data['from_email'] except KeyError as error: new_msg = 'The conversation message must have a from_email, {}'.format( error) six.reraise(KeyError, KeyError(new_msg), sys.exc_info()[2]) check_email(data['from_email']) try: test = data['read'] except KeyError as error: new_msg = 'The conversation message must have a read, {}'.format( error) six.reraise(KeyError, KeyError(new_msg), sys.exc_info()[2]) if data['read'] not in [True, False]: raise TypeError( 'The conversation message read must be True or False') response = self._mc_client._post(url=self._build_path( conversation_id, 'messages'), data=data) if response is not None: self.message_id = response['id'] else: self.message_id = None return response
async def create(self, workflow_id, data): """ Remove a subscriber from a specific Automation workflow. You can remove a subscriber at any point in an Automation workflow, regardless of how many emails they’ve been sent from that workflow. Once they’re removed, they can never be added back to the same workflow. :param workflow_id: The unique id for the Automation workflow. :type workflow_id: :py:class:`str` :param data: The request body parameters :type data: :py:class:`dict` data = { "email_address": string* } """ self.workflow_id = workflow_id if 'email_address' not in data: raise KeyError( 'The automation removed subscriber must have an email_address') check_email(data['email_address']) return await self._mc_client._post(url=self._build_path( workflow_id, 'removed-subscribers'), data=data)
def create(self, store_id, data): """ Add a new customer to a store. :param store_id: The store id. :type store_id: :py:class:`str` :param data: The request body parameters :type data: :py:class:`dict` data = { "id": string*, "email_address": string*, "opt_in_status": boolean* } """ self.store_id = store_id try: test = data['id'] except KeyError as error: error.message += ' The store customer must have an id' raise try: test = data['email_address'] except KeyError as error: error.message += ' The store customer must have an email_address' raise check_email(data['email_address']) try: test = data['opt_in_status'] except KeyError as error: error.message += ' The store customer must have an opt_in_status' raise if data['opt_in_status'] not in [True, False]: raise TypeError('The opt_in_status must be True or False') response = self._mc_client._post(url=self._build_path(store_id, 'customers'), data=data) self.customer_id = response['id'] return response
def create(self, data): """ Create a new MailChimp campaign. The ValueError raised by an invalid type in data does not mention 'absplit' as a potential value because the documentation indicates that the absplit type has been deprecated. :param data: The request body parameters :type data: :py:class:`dict` data = { "recipients": object* { "list_id": string* }, "settings": object* { "subject_line": string*, "from_name": string*, "reply_to": string* }, "variate_settings": object* (Required if type is "variate") { "winner_criteria": string* (Must be one of "opens", "clicks", "total_revenue", or "manual") }, "rss_opts": object* (Required if type is "rss") { "feed_url": string*, "frequency": string* (Must be one of "daily", "weekly", or "monthly") }, "type": string* (Must be one of "regular", "plaintext", "rss", "variate", or "absplit") } """ if 'recipients' not in data: raise KeyError('The campaign must have recipients') if 'list_id' not in data['recipients']: raise KeyError('The campaign recipients must have a list_id') if 'settings' not in data: raise KeyError('The campaign must have settings') if 'subject_line' not in data['settings']: raise KeyError('The campaign settings must have a subject_line') if 'from_name' not in data['settings']: raise KeyError('The campaign settings must have a from_name') if 'reply_to' not in data['settings']: raise KeyError('The campaign settings must have a reply_to') check_email(data['settings']['reply_to']) if 'type' not in data: raise KeyError('The campaign must have a type') if not data['type'] in [ 'regular', 'plaintext', 'rss', 'variate', 'abspilt' ]: raise ValueError( 'The campaign type must be one of "regular", "plaintext", "rss", or "variate"' ) if data['type'] == 'variate': if 'variate_settings' not in data: raise KeyError( 'The variate campaign must have variate_settings') if 'winner_criteria' not in data['variate_settings']: raise KeyError( 'The campaign variate_settings must have a winner_criteria' ) if data['variate_settings']['winner_criteria'] not in [ 'opens', 'clicks', 'total_revenue', 'manual' ]: raise ValueError( 'The campaign variate_settings ' 'winner_criteria must be one of "opens", "clicks", "total_revenue", or "manual"' ) if data['type'] == 'rss': if 'rss_opts' not in data: raise KeyError('The rss campaign must have rss_opts') if 'feed_url' not in data['rss_opts']: raise KeyError('The campaign rss_opts must have a feed_url') if not data['rss_opts']['frequency'] in [ 'daily', 'weekly', 'monthly' ]: raise ValueError( 'The rss_opts frequency must be one of "daily", "weekly", or "monthly"' ) response = self._mc_client._post(url=self._build_path(), data=data) if response is not None: self.campaign_id = response['id'] else: self.campaign_id = None return response
def create(self, data): """ Create a new list in your MailChimp account. :param data: The request body parameters :type data: :py:class:`dict` data = { "name": string*, "contact": object* { "company": string*, "address1": string*, "city": string*, "state": string*, "zip": string*, "country": string* }, "permision_reminder": string*, "campaign_defaults": object* { "from_name": string*, "from_email": string*, "subject": string*, "language": string* }, "email_type_option": boolean } """ if 'name' not in data: raise KeyError('The list must have a name') if 'contact' not in data: raise KeyError('The list must have a contact') if 'company' not in data['contact']: raise KeyError('The list contact must have a company') if 'address1' not in data['contact']: raise KeyError('The list contact must have a address1') if 'city' not in data['contact']: raise KeyError('The list contact must have a city') if 'state' not in data['contact']: raise KeyError('The list contact must have a state') if 'zip' not in data['contact']: raise KeyError('The list contact must have a zip') if 'country' not in data['contact']: raise KeyError('The list contact must have a country') if 'permission_reminder' not in data: raise KeyError('The list must have a permission_reminder') if 'campaign_defaults' not in data: raise KeyError('The list must have a campaign_defaults') if 'from_name' not in data['campaign_defaults']: raise KeyError('The list campaign_defaults must have a from_name') if 'from_email' not in data['campaign_defaults']: raise KeyError('The list campaign_defaults must have a from_email') check_email(data['campaign_defaults']['from_email']) if 'subject' not in data['campaign_defaults']: raise KeyError('The list campaign_defaults must have a subject') if 'language' not in data['campaign_defaults']: raise KeyError('The list campaign_defaults must have a language') if 'email_type_option' not in data: raise KeyError('The list must have an email_type_option') if data['email_type_option'] not in [True, False]: raise TypeError('The list email_type_option must be True or False') response = self._mc_client._post(url=self._build_path(), data=data) if response is not None: self.list_id = response['id'] else: self.list_id = None return response
def update(self, list_id, data): """ Update the settings for a specific list. :param list_id: The unique id for the list. :type list_id: :py:class:`str` :param data: The request body parameters :type data: :py:class:`dict` data = { "name": string*, "contact": object* { "company": string*, "address1": string*, "city": string*, "state": string*, "zip": string*, "country": string* }, "permission_reminder": string*, "campaign_defaults": object* { "from_name": string*, "from_email": string*, "subject": string*, "language": string* }, "email_type_option": boolean } """ self.list_id = list_id if 'name' not in data: raise KeyError('The list must have a name') if 'contact' not in data: raise KeyError('The list must have a contact') if 'company' not in data['contact']: raise KeyError('The list contact must have a company') if 'address1' not in data['contact']: raise KeyError('The list contact must have a address1') if 'city' not in data['contact']: raise KeyError('The list contact must have a city') if 'state' not in data['contact']: raise KeyError('The list contact must have a state') if 'zip' not in data['contact']: raise KeyError('The list contact must have a zip') if 'country' not in data['contact']: raise KeyError('The list contact must have a country') if 'permission_reminder' not in data: raise KeyError('The list must have a permission_reminder') if 'campaign_defaults' not in data: raise KeyError('The list must have a campaign_defaults') if 'from_name' not in data['campaign_defaults']: raise KeyError('The list campaign_defaults must have a from_name') if 'from_email' not in data['campaign_defaults']: raise KeyError('The list campaign_defaults must have a from_email') check_email(data['campaign_defaults']['from_email']) if 'subject' not in data['campaign_defaults']: raise KeyError('The list campaign_defaults must have a subject') if 'language' not in data['campaign_defaults']: raise KeyError('The list campaign_defaults must have a language') if 'email_type_option' not in data: raise KeyError('The list must have an email_type_option') if data['email_type_option'] not in [True, False]: raise TypeError('The list email_type_option must be True or False') return self._mc_client._patch(url=self._build_path(list_id), data=data)
def create(self, data): """ Create a new list in your MailChimp account. :param data: The request body parameters :type data: :py:class:`dict` data = { "name": string*, "contact": object* { "company": string*, "address1": string*, "city": string*, "state": string*, "zip": string*, "country": string* }, "permission_reminder": string*, "campaign_defaults": object* { "from_name": string*, "from_email": string*, "subject": string*, "language": string* }, "email_type_option": boolean } """ if 'name' not in data: raise KeyError('The list must have a name') if 'contact' not in data: raise KeyError('The list must have a contact') if 'company' not in data['contact']: raise KeyError('The list contact must have a company') if 'address1' not in data['contact']: raise KeyError('The list contact must have a address1') if 'city' not in data['contact']: raise KeyError('The list contact must have a city') if 'state' not in data['contact']: raise KeyError('The list contact must have a state') if 'zip' not in data['contact']: raise KeyError('The list contact must have a zip') if 'country' not in data['contact']: raise KeyError('The list contact must have a country') if 'permission_reminder' not in data: raise KeyError('The list must have a permission_reminder') if 'campaign_defaults' not in data: raise KeyError('The list must have a campaign_defaults') if 'from_name' not in data['campaign_defaults']: raise KeyError('The list campaign_defaults must have a from_name') if 'from_email' not in data['campaign_defaults']: raise KeyError('The list campaign_defaults must have a from_email') check_email(data['campaign_defaults']['from_email']) if 'subject' not in data['campaign_defaults']: raise KeyError('The list campaign_defaults must have a subject') if 'language' not in data['campaign_defaults']: raise KeyError('The list campaign_defaults must have a language') if 'email_type_option' not in data: raise KeyError('The list must have an email_type_option') if data['email_type_option'] not in [True, False]: raise TypeError('The list email_type_option must be True or False') response = self._mc_client._post(url=self._build_path(), data=data) if response is not None: self.list_id = response['id'] else: self.list_id = None return response
def create(self, data): """ Create a new MailChimp campaign. The ValueError raised by an invalid type in data does not mention 'absplit' as a potential value because the documentation indicates that the absplit type has been deprecated. :param data: The request body parameters :type data: :py:class:`dict` data = { "recipients": object* { "list_id": string* }, "settings": object* { "subject_line": string*, "from_name": string*, "reply_to": string* }, "variate_settings": object* (Required if type is "variate") { "winner_criteria": string* (Must be one of "opens", "clicks", "total_revenue", or "manual") }, "rss_opts": object* (Required if type is "rss") { "feed_url": string*, "frequency": string* (Must be one of "daily", "weekly", or "monthly") }, "type": string* (Must be one of "regular", "plaintext", "rss", "variate", or "absplit") } """ try: test = data['recipients'] except KeyError as error: error.message += ' The campaign must have recipients' raise for recipient in data['recipients']: try: test = recipient['list_id'] except KeyError as error: error.message += ' The campaign recipient must have a list_id' raise try: test = data['settings']['subject_line'] except KeyError as error: error.message += ' The campaign settings must have a subject_line' raise try: test = data['settings']['from_name'] except KeyError as error: error.message += ' The campaign settings must have a from_name' raise try: test = data['settings']['reply_to'] except KeyError as error: error.message += ' The campaign settings must have a reply_to' raise check_email(data['settings']['reply_to']) try: test = data['type'] except KeyError as error: error.message += ' The campaign must have a type' raise if not data['type'] in ['regular', 'plaintext', 'rss', 'variate', 'abspilt']: raise ValueError('The campaign type must be one of "regular", "plaintext", "rss", or "variate"') if data['type'] == 'variate': try: test = data['variate_settings']['winner_criteria'] except KeyError as error: error.message += 'The campaign variate_settings must have a winner_criteria' raise if data['variate_settings']['winner_criteria'] not in ['opens', 'clicks', 'total_revenue', 'manual']: raise ValueError('The campaign variate_settings ' 'winner_criteria must be one of "opens", "clicks", "total_revenue", or "manual"') if data['type'] == 'rss': try: test = data['rss_opts']['feed_url'] except KeyError as error: error.message += ' The campaign rss_opts must have a feed_url' raise if not data['rss_opts']['frequency'] in ['daily', 'weekly', 'monthly']: raise ValueError('The rss_opts frequency must be one of "daily", "weekly", or "monthly"') response = self._mc_client._post(url=self._build_path(), data=data) self.campaign_id = response['id'] return response
def create(self, data): """ Create a new list in your MailChimp account. :param data: The request body parameters :type data: :py:class:`dict` data = { "name": string*, "contact": object* { "company": string*, "address1": string*, "city": string*, "state": string*, "zip": string*, "country": string* }, "permision_reminder": string*, "campaign_defaults": object* { "from_name": string*, "from_email": string*, "subject": string*, "language": string* }, "email_type_option": boolean } """ try: test = data['name'] except KeyError as error: new_msg = 'The list must have a name, {}'.format(error) six.reraise(KeyError, KeyError(new_msg), sys.exc_info()[2]) try: test = data['contact'] except KeyError as error: new_msg = 'The list must have a contact, {}'.format(error) six.reraise(KeyError, KeyError(new_msg), sys.exc_info()[2]) try: test = data['contact']['company'] except KeyError as error: new_msg = 'The list contact must have a company, {}'.format(error) six.reraise(KeyError, KeyError(new_msg), sys.exc_info()[2]) try: test = data['contact']['address1'] except KeyError as error: new_msg = 'The list contact must have a address1, {}'.format(error) six.reraise(KeyError, KeyError(new_msg), sys.exc_info()[2]) try: test = data['contact']['city'] except KeyError as error: new_msg = 'The list contact must have a city, {}'.format(error) six.reraise(KeyError, KeyError(new_msg), sys.exc_info()[2]) try: test = data['contact']['state'] except KeyError as error: new_msg = 'The list contact must have a state, {}'.format(error) six.reraise(KeyError, KeyError(new_msg), sys.exc_info()[2]) try: test = data['contact']['zip'] except KeyError as error: new_msg = 'The list contact must have a zip, {}'.format(error) six.reraise(KeyError, KeyError(new_msg), sys.exc_info()[2]) try: test = data['contact']['country'] except KeyError as error: new_msg = 'The list contact must have a country, {}'.format(error) six.reraise(KeyError, KeyError(new_msg), sys.exc_info()[2]) try: test = data['permission_reminder'] except KeyError as error: new_msg = 'The list must have a permission_reminder, {}'.format( error) six.reraise(KeyError, KeyError(new_msg), sys.exc_info()[2]) try: test = data['campaign_defaults'] except KeyError as error: new_msg = 'The list must have a campaign_defaults, {}'.format( error) six.reraise(KeyError, KeyError(new_msg), sys.exc_info()[2]) try: test = data['campaign_defaults']['from_name'] except KeyError as error: new_msg = 'The list campaign_defaults must have a from_name, {}'.format( error) six.reraise(KeyError, KeyError(new_msg), sys.exc_info()[2]) try: test = data['campaign_defaults']['from_email'] except KeyError as error: new_msg = 'The list campaign_defaults must have a from_email, {}'.format( error) six.reraise(KeyError, KeyError(new_msg), sys.exc_info()[2]) check_email(data['campaign_defaults']['from_email']) try: test = data['campaign_defaults']['subject'] except KeyError as error: new_msg = 'The list campaign_defaults must have a subject, {}'.format( error) six.reraise(KeyError, KeyError(new_msg), sys.exc_info()[2]) try: test = data['campaign_defaults']['language'] except KeyError as error: new_msg = 'The list campaign_defaults must have a language, {}'.format( error) six.reraise(KeyError, KeyError(new_msg), sys.exc_info()[2]) try: test = data['email_type_option'] except KeyError as error: new_msg = 'The list must have an email_type_option, {}'.format( error) six.reraise(KeyError, KeyError(new_msg), sys.exc_info()[2]) if data['email_type_option'] not in [True, False]: raise TypeError('The list email_type_option must be True or False') response = self._mc_client._post(url=self._build_path(), data=data) if response is not None: self.list_id = response['id'] else: self.list_id = None return response
def check(list_id, data): # MailChimp check email. check_email(data["email_address"])
def update(self, list_id, data): """ Update the settings for a specific list. :param list_id: The unique id for the list. :type list_id: :py:class:`str` :param data: The request body parameters :type data: :py:class:`dict` data = { "name": string*, "contact": object* { "company": string*, "address1": string*, "city": string*, "state": string*, "zip": string*, "country": string* }, "permision_reminder": string*, "campaign_defaults": object* { "from_name": string*, "from_email": string*, "subject": string*, "language": string* }, "email_type_option": boolean } """ self.list_id = list_id try: test = data['name'] except KeyError as error: new_msg = 'The list must have a name, {}'.format(error) six.reraise(KeyError, KeyError(new_msg), sys.exc_info()[2]) try: test = data['contact'] except KeyError as error: new_msg = 'The list must have a contact, {}'.format(error) six.reraise(KeyError, KeyError(new_msg), sys.exc_info()[2]) try: test = data['contact']['company'] except KeyError as error: new_msg = 'The list contact must have a company, {}'.format(error) six.reraise(KeyError, KeyError(new_msg), sys.exc_info()[2]) try: test = data['contact']['address1'] except KeyError as error: new_msg = 'The list contact must have a address1, {}'.format(error) six.reraise(KeyError, KeyError(new_msg), sys.exc_info()[2]) try: test = data['contact']['city'] except KeyError as error: new_msg = 'The list contact must have a city, {}'.format(error) six.reraise(KeyError, KeyError(new_msg), sys.exc_info()[2]) try: test = data['contact']['state'] except KeyError as error: new_msg = 'The list contact must have a state, {}'.format(error) six.reraise(KeyError, KeyError(new_msg), sys.exc_info()[2]) try: test = data['contact']['zip'] except KeyError as error: new_msg = 'The list contact must have a zip, {}'.format(error) six.reraise(KeyError, KeyError(new_msg), sys.exc_info()[2]) try: test = data['contact']['country'] except KeyError as error: new_msg = 'The list contact must have a country, {}'.format(error) six.reraise(KeyError, KeyError(new_msg), sys.exc_info()[2]) try: test = data['permission_reminder'] except KeyError as error: new_msg = 'The list must have a permission_reminder, {}'.format( error) six.reraise(KeyError, KeyError(new_msg), sys.exc_info()[2]) try: test = data['campaign_defaults'] except KeyError as error: new_msg = 'The list must have a campaign_defaults, {}'.format( error) six.reraise(KeyError, KeyError(new_msg), sys.exc_info()[2]) try: test = data['campaign_defaults']['from_name'] except KeyError as error: new_msg = 'The list campaign_defaults must have a from_name, {}'.format( error) six.reraise(KeyError, KeyError(new_msg), sys.exc_info()[2]) try: test = data['campaign_defaults']['from_email'] except KeyError as error: new_msg = 'The list campaign_defaults must have a from_email, {}'.format( error) six.reraise(KeyError, KeyError(new_msg), sys.exc_info()[2]) check_email(data['campaign_defaults']['from_email']) try: test = data['campaign_defaults']['subject'] except KeyError as error: new_msg = 'The list campaign_defaults must have a subject, {}'.format( error) six.reraise(KeyError, KeyError(new_msg), sys.exc_info()[2]) try: test = data['campaign_defaults']['language'] except KeyError as error: new_msg = 'The list campaign_defaults must have a language, {}'.format( error) six.reraise(KeyError, KeyError(new_msg), sys.exc_info()[2]) try: test = data['email_type_option'] except KeyError as error: new_msg = 'The list must have an email_type_option, {}'.format( error) six.reraise(KeyError, KeyError(new_msg), sys.exc_info()[2]) if data['email_type_option'] not in [True, False]: raise TypeError('The list email_type_option must be True or False') return self._mc_client._patch(url=self._build_path(list_id), data=data)
def create(self, data): """ Create a new list in your MailChimp account. :param data: The request body parameters :type data: :py:class:`dict` data = { "name": string*, "contact": object* { "company": string*, "address1": string*, "city": string*, "state": string*, "zip": string*, "country": string* }, "permision_reminder": string*, "campaign_defaults": object* { "from_name": string*, "from_email": string*, "subject": string*, "language": string* }, "email_type_option": boolean } """ try: test = data['name'] except KeyError as error: error.message += ' The list must have a name' raise try: test = data['contact'] except KeyError as error: error.message += ' The list must have a contact' raise try: test = data['contact']['company'] except KeyError as error: error.message += ' The list contact must have a company' raise try: test = data['contact']['address1'] except KeyError as error: error.message += ' The list contact must have a address1' raise try: test = data['contact']['city'] except KeyError as error: error.message += ' The list contact must have a city' raise try: test = data['contact']['state'] except KeyError as error: error.message += ' The list contact must have a state' raise try: test = data['contact']['zip'] except KeyError as error: error.message += ' The list contact must have a zip' raise try: test = data['contact']['country'] except KeyError as error: error.message += ' The list contact must have a country' raise try: test = data['permission_reminder'] except KeyError as error: error.message += ' The list must have a permission_reminder' raise try: test = data['campaign_defaults'] except KeyError as error: error.message += ' The list must have a campaign_defaults' raise try: test = data['campaign_defaults']['from_name'] except KeyError as error: error.message += ' The list campaign_defaults must have a from_name' raise try: test = data['campaign_defaults']['from_email'] except KeyError as error: error.message += ' The list campaign_defaults must have a from_email' raise check_email(data['campaign_defaults']['from_email']) try: test = data['campaign_defaults']['subject'] except KeyError as error: error.message += ' The list campaign_defaults must have a subject' raise try: test = data['campaign_defaults']['language'] except KeyError as error: error.message += ' The list campaign_defaults must have a language' raise try: test = data['email_type_option'] except KeyError as error: error.message += ' The list must have an email_type_option' raise if data['email_type_option'] not in [True, False]: raise TypeError('The list email_type_option must be True or False') response = self._mc_client._post(url=self._build_path(), data=data) self.list_id = response['id'] return response
def update(self, list_id, data): """ Update the settings for a specific list. :param list_id: The unique id for the list. :type list_id: :py:class:`str` :param data: The request body parameters :type data: :py:class:`dict` data = { "name": string*, "contact": object* { "company": string*, "address1": string*, "city": string*, "state": string*, "zip": string*, "country": string* }, "permision_reminder": string*, "campaign_defaults": object* { "from_name": string*, "from_email": string*, "subject": string*, "language": string* }, "email_type_option": boolean } """ self.list_id = list_id try: test = data['name'] except KeyError as error: error.message += ' The list must have a name' raise try: test = data['contact'] except KeyError as error: error.message += ' The list must have a contact' raise try: test = data['contact']['company'] except KeyError as error: error.message += ' The list contact must have a company' raise try: test = data['contact']['address1'] except KeyError as error: error.message += ' The list contact must have a address1' raise try: test = data['contact']['city'] except KeyError as error: error.message += ' The list contact must have a city' raise try: test = data['contact']['state'] except KeyError as error: error.message += ' The list contact must have a state' raise try: test = data['contact']['zip'] except KeyError as error: error.message += ' The list contact must have a zip' raise try: test = data['contact']['country'] except KeyError as error: error.message += ' The list contact must have a country' raise try: test = data['permission_reminder'] except KeyError as error: error.message += ' The list must have a permission_reminder' raise try: test = data['campaign_defaults'] except KeyError as error: error.message += ' The list must have a campaign_defaults' raise try: test = data['campaign_defaults']['from_name'] except KeyError as error: error.message += ' The list campaign_defaults must have a from_name' raise try: test = data['campaign_defaults']['from_email'] except KeyError as error: error.message += ' The list campaign_defaults must have a from_email' raise check_email(data['campaign_defaults']['from_email']) try: test = data['campaign_defaults']['subject'] except KeyError as error: error.message += ' The list campaign_defaults must have a subject' raise try: test = data['campaign_defaults']['language'] except KeyError as error: error.message += ' The list campaign_defaults must have a language' raise try: test = data['email_type_option'] except KeyError as error: error.message += ' The list must have an email_type_option' raise if data['email_type_option'] not in [True, False]: raise TypeError('The list email_type_option must be True or False') return self._mc_client._patch(url=self._build_path(list_id), data=data)