For more information about MailerLite API, please visit the following link:
API keys are a quick way to implement machine-to-machine authentication without any direct inputs from a human beyond initial setup.
For more information how to obtain an API key visit the following link
- MailerLite Python SDK
Please run the following command:
python -m pip install mailerlite
The first thing that you need to do is to import mailerlite
into your project and to instantiate the client by passing your API key:
import mailerlite as MailerLite
client = MailerLite.Client({
'api_key': 'your-api-key'
})
MailerLite API supports versioning, so you can pass additional argument to specify the API version:
import mailerlite as MailerLite
client = MailerLite.Client({
'api_key': 'your-api-key',
'api_version': '2038-01-19'
})
import mailerlite as MailerLite
client = MailerLite.Client({
'api_key': 'your-api-key'
})
response = client.subscribers.list(limit=10, page=1, filter={'status': 'active'})
import mailerlite as MailerLite
client = MailerLite.Client({
'api_key': 'your-api-key'
})
response = client.subscribers.create('some@email.com', fields={'name': 'John', 'last_name': 'Doe'}, ip_address='1.2.3.4', optin_ip='1.2.3.4')
import mailerlite as MailerLite
client = MailerLite.Client({
'api_key': 'your-api-key'
})
response = client.subscribers.update('some@email.com', fields={'name': 'New', 'last_name': 'Name'}, ip_address='1.2.3.5', optin_ip='1.2.3.5')
import mailerlite as MailerLite
client = MailerLite.Client({
'api_key': 'your-api-key'
})
response = client.subscribers.get('some@email.com')
import mailerlite as MailerLite
client = MailerLite.Client({
'api_key': 'your-api-key'
})
subscriber_id = 1234567890
response = client.subscribers.delete(subscriber_id)
import mailerlite as MailerLite
client = MailerLite.Client({
'api_key': 'your-api-key'
})
subscriber_id = 1234567890
response = client.subscribers.forget(subscriber_id)
import mailerlite as MailerLite
client = MailerLite.Client({
'api_key': 'your-api-key'
})
response = client.groups.list(limit=10, page=1, filter={'name': 'My'}, sort='name')
import mailerlite as MailerLite
client = MailerLite.Client({
'api_key': 'your-api-key'
})
group_name = 'My Group'
response = client.groups.create(group_name)
import mailerlite as MailerLite
client = MailerLite.Client({
'api_key': 'your-api-key'
})
group_id = 1234567
group_name = 'My New Group'
response = client.groups.update(group_id, group_name)
import mailerlite as MailerLite
client = MailerLite.Client({
'api_key': 'your-api-key'
})
group_id = 1234567
response = client.groups.delete(group_id)
import mailerlite as MailerLite
client = MailerLite.Client({
'api_key': 'your-api-key'
})
group_id = 1234567
response = client.groups.get_group_subscribers(group_id, page=1, limit=10, filter={'status': 'active'})
import mailerlite as MailerLite
client = MailerLite.Client({
'api_key': 'your-api-key'
})
subscriber_id = 111222
group_id = 1234567
response = client.subscribers.assign_subscriber_to_group(subscriber_id, group_id)
import mailerlite as MailerLite
client = MailerLite.Client({
'api_key': 'your-api-key'
})
subscriber_id = 111222
group_id = 1234567
response = client.subscribers.unassign_subscriber_from_group(subscriber_id, group_id)
import mailerlite as MailerLite
client = MailerLite.Client({
'api_key': 'your-api-key'
})
response = client.segments.list(limit=10, page=1)
import mailerlite as MailerLite
client = MailerLite.Client({
'api_key': 'your-api-key'
})
segment_id = 123456
name = "My New Segment Name"
response = client.segments.update(segment_id, name)
import mailerlite as MailerLite
client = MailerLite.Client({
'api_key': 'your-api-key'
})
segment_id = 123456
response = client.segments.delete(segment_id)
import mailerlite as MailerLite
client = MailerLite.Client({
'api_key': 'your-api-key'
})
segment_id = 123456
response = client.segments.get_subscribers(segment_id, limit=10, filter={'status': 'active'})
import mailerlite as MailerLite
client = MailerLite.Client({
'api_key': 'your-api-key'
})
response = client.fields.list(limit=10, page=1, sort='name', filter={'keyword': 'abc', 'type': 'text'})
import mailerlite as MailerLite
client = MailerLite.Client({
'api_key': 'your-api-key'
})
name = 'My Field'
type = 'text
response = client.fields.create(name, type)
import mailerlite as MailerLite
client = MailerLite.Client({
'api_key': 'your-api-key'
})
field_id = 123456
name = 'My New Field'
response = client.fields.update(field_id, name)
import mailerlite as MailerLite
client = MailerLite.Client({
'api_key': 'your-api-key'
})
field_id = 123456
response = client.fields.delete(field_id)
import mailerlite as MailerLite
client = MailerLite.Client({
'api_key': 'your-api-key'
})
response = client.automations.list(limit=10, page=1, filter={'enabled': True, 'name': 'some name', 'group': 123456})
import mailerlite as MailerLite
client = MailerLite.Client({
'api_key': 'your-api-key'
})
automation_id = 123456
response = client.automations.get(automation_id)
import mailerlite as MailerLite
client = MailerLite.Client({
'api_key': 'your-api-key'
})
automation_id = 123456
response = client.automations.activity(automation_id, page=1, limit=10, filter={'status': 'active', 'date_from': '2022-12-20', 'date_to': '2022-12-31'})
import mailerlite as MailerLite
client = MailerLite.Client({
'api_key': 'your-api-key'
})
response = client.campaigns.list(limit=10, page=1, filter={'status': 'ready', 'type': 'regular'})
import mailerlite as MailerLite
client = MailerLite.Client({
'api_key': 'your-api-key'
})
campaign_id = 123456
response = client.campaigns.get(campaign_id)
import mailerlite as MailerLite
client = MailerLite.Client({
'api_key': 'your-api-key'
})
params = {
"name": "Test Campaign",
"language_id": 1,
"type": "regular",
"emails": [{
"subject": "This is a test campaign",
"from_name": "Test Man",
"from": "testuser@mailerlite.com",
"content": "Hi there, this is a test campaign!"
}]
}
response = client.campaigns.create(params)
import mailerlite as MailerLite
client = MailerLite.Client({
'api_key': 'your-api-key'
})
campaign_id = 123456
params = {
"name": "New Campaign Name",
"language_id": 2,
"emails": [{
"subject": "This is a test campaign",
"from_name": "Test Man",
"from": "testuser@mailerlite.com",
"content": "Hi there, this is a test campaign!"
}]
}
response = client.campaigns.update(campaign_id, params)
import mailerlite as MailerLite
client = MailerLite.Client({
'api_key': 'your-api-key'
})
campaign_id = 123456
params = {
"delivery": "scheduled",
"schedule": {
"date": "2022-12-31",
"hours": "22",
"minutes": "00"
}
}
response = client.campaigns.schedule(campaign_id, params)
import mailerlite as MailerLite
client = MailerLite.Client({
'api_key': 'your-api-key'
})
campaign_id = 123456
response = client.campaigns.cancel(campaign_id)
import mailerlite as MailerLite
client = MailerLite.Client({
'api_key': 'your-api-key'
})
campaign_id = 123456
response = client.campaigns.delete(campaign_id)
import mailerlite as MailerLite
client = MailerLite.Client({
'api_key': 'your-api-key'
})
campaign_id = 123456
response = client.campaigns.activity(campaign_id)
import mailerlite as MailerLite
client = MailerLite.Client({
'api_key': 'your-api-key'
})
response = client.forms.list(limit=10, page=1, sort='name', filter={'name': 'form name'})
import mailerlite as MailerLite
client = MailerLite.Client({
'api_key': 'your-api-key'
})
form_id = 123456
response = client.forms.get(form_id)
import mailerlite as MailerLite
client = MailerLite.Client({
'api_key': 'your-api-key'
})
form_id = 123456
name = 'New Form Name'
response = client.forms.update(form_id, name)
import mailerlite as MailerLite
client = MailerLite.Client({
'api_key': 'your-api-key'
})
form_id = 123456
response = client.forms.delete(form_id)
import mailerlite as MailerLite
client = MailerLite.Client({
'api_key': 'your-api-key'
})
form_id = 123456
response = client.forms.get_subscribers(form_id, page=1, limit=10, filter={'status': 'active'})
import mailerlite as MailerLite
client = MailerLite.Client({
'api_key': 'your-api-key'
})
response = client.webhooks.list()
import mailerlite as MailerLite
client = MailerLite.Client({
'api_key': 'your-api-key'
})
webhook_id = 123456
response = client.webhooks.get(webhook_id)
import mailerlite as MailerLite
client = MailerLite.Client({
'api_key': 'your-api-key'
})
events = [
'subscriber.created',
'subscriber.updated',
'subscriber.unsubscribed'
]
url = 'https://my-url.com'
name = 'Webhook name'
response = client.webhooks.create(events, url, name)
import mailerlite as MailerLite
client = MailerLite.Client({
'api_key': 'your-api-key'
})
webhook_id = 123456
events = [
'subscriber.created',
'subscriber.updated',
'subscriber.unsubscribed'
]
url = 'https://my-url.com'
name = 'Webhook name'
enabled = False
response = client.webhooks.update(webhook_id, events, url, name, enabled)
import mailerlite as MailerLite
client = MailerLite.Client({
'api_key': 'your-api-key'
})
webhook_id = 123456
response = client.webhooks.delete(webhook_id)
import mailerlite as MailerLite
client = MailerLite.Client({
'api_key': 'your-api-key'
})
response = client.timezone.list()
import mailerlite as MailerLite
client = MailerLite.Client({
'api_key': 'your-api-key'
})
response = client.campaigns.languages()