python requests library
pip install sendwithus
For all examples, assume:
import sendwithus
api = sendwithus.api(api_key='YOUR-API-KEY')
api.templates()
api.create_template(
name='Email Name',
subject='Email Subject',
html='<html><head></head><body>Valid HTML</body></html>',
text='Optional text content')
We validate all HTML and will return an error if it's invalid.
r.status_code
# 400
r.content
# 'email html failed to validate'
The email_data
field is optional, but highly recommended!
r = api.send(
email_id='YOUR-EMAIL-ID',
recipient={'address': '[email protected]'})
print r.status_code
# 200
r = api.send(
email_id='YOUR-EMAIL-ID',
recipient={'address': '[email protected]'},
email_data={ 'first_name': 'Matt' })
print r.status_code
# 200
The sender['address']
is a required sender field
r = api.send(
email_id='YOUR-EMAIL-ID',
recipient={ 'name': 'Matt',
'address': '[email protected]'},
email_data={ 'first_name': 'Matt' },
sender={ 'address':'[email protected]' })
print r.status_code
# 200
sender['name']
and sender['reply_to']
are both optional
r = api.send(
email_id='YOUR-EMAIL-ID',
recipient={ 'name': 'Matt',
'address': '[email protected]'},
email_data={ 'first_name': 'Matt' },
sender={ 'name': 'Company',
'address':'[email protected]',
'reply_to':'[email protected]'})
print r.status_code
# 200
r = api.send(
email_id='YOUR-EMAIL-ID',
recipient={'name': 'Matt',
'address': '[email protected]'},
cc=[
{'address': '[email protected]'},
{'address': '[email protected]'}
])
print r.status_code
# 200
r = api.send(
email_id='YOUR-EMAIL-ID',
recipient={'name': 'Matt',
'address': '[email protected]'},
bcc=[
{'address': '[email protected]'},
{'address': '[email protected]'}
])
print r.status_code
# 200
r = api.send(
email_id='YOUR-EMAIL-ID',
recipient={'name': 'Matt',
'address': '[email protected]'},
esp_account='esp_1234asdf1234')
print r.status_code
# 200
You can deactivate pending drip campaign emails for a customer
api.drip_deactivate('[email protected]')
List all drip campaigns for the current profile
api.list_drip_campaigns()
Starts a customer on the first step of a specified drip campaign
api.start_on_drip_campaign('[email protected]', 'dc_1234asdf1234')
You may specify extra data to be merged into the templates in the drip campaign
api.start_on_drip_campaign('[email protected]', 'dc_1234asdf1234', email_data={'color': 'blue'})
Deactivates all pending emails for a customer on a specified drip campaign
api.remove_from_drip_campaign('[email protected]', 'dc_1234asdf1234')
api.drip_campaign_details('dc_1234asdf1234')
api.drip_campaign_customers('dc_1234asdf1234')
api.drip_campaign_step_customers('dc_1234asdf1234', 'dcs_jklqwer567')
You can use the same endpoint to create or update a customer. Sendwithus will peform a merge of the data on the customer profile, preferring the new data.
api.customer_create('[email protected]', data={'first_name': 'Matt'})
api.customer_delete('[email protected]')
You can use the Segments api to send a template to all customers who match a
segment. The Segment must be created in the Sendwithus dashboard, which is
where you will find the segment_id
for use in this api.
api.send_segment('tem_12345', 'seg_1245')
You may specify extra data to be merged into the template, alongside the individual customer profiles
api.send_segment('tem_12345', 'seg_12345', email_data={'color': 'blue'})
>>> r.status_code
200
>>> r.json().get('success')
True
>>> r.json().get('status')
u'OK'
>>> r.json().get('receipt_id')
u'numeric-receipt-id'
-
malformed request
>>> r.status_code 400
-
bad api key
>>> r.status_code 403
python setup.py test
python setup.py sdist upload