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 mailerliteThe first thing that you need to do is to import mailerlite into your project and to instantiate the client by passing your API key:
importmailerliteasMailerLiteclient=MailerLite.Client({
'api_key': 'your-api-key'
})MailerLite API supports versioning, so you can pass additional argument to specify the API version:
importmailerliteasMailerLiteclient=MailerLite.Client({
'api_key': 'your-api-key',
'api_version': '2038-01-19'
})importmailerliteasMailerLiteclient=MailerLite.Client({
'api_key': 'your-api-key'
})
response=client.subscribers.list(limit=10, page=1, filter={'status': 'active'})importmailerliteasMailerLiteclient=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')importmailerliteasMailerLiteclient=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')importmailerliteasMailerLiteclient=MailerLite.Client({
'api_key': 'your-api-key'
})
response=client.subscribers.get('some@email.com')importmailerliteasMailerLiteclient=MailerLite.Client({
'api_key': 'your-api-key'
})
subscriber_id=1234567890response=client.subscribers.delete(subscriber_id)importmailerliteasMailerLiteclient=MailerLite.Client({
'api_key': 'your-api-key'
})
response=client.groups.list(limit=10, page=1, filter={'name': 'My'}, sort='name')importmailerliteasMailerLiteclient=MailerLite.Client({
'api_key': 'your-api-key'
})
group_name='My Group'response=client.groups.create(group_name)importmailerliteasMailerLiteclient=MailerLite.Client({
'api_key': 'your-api-key'
})
group_id=1234567group_name='My New Group'response=client.groups.update(group_id, group_name)importmailerliteasMailerLiteclient=MailerLite.Client({
'api_key': 'your-api-key'
})
group_id=1234567response=client.groups.delete(group_id)importmailerliteasMailerLiteclient=MailerLite.Client({
'api_key': 'your-api-key'
})
group_id=1234567response=client.groups.get_group_subscribers(group_id, page=1, limit=10, filter={'status': 'active'})importmailerliteasMailerLiteclient=MailerLite.Client({
'api_key': 'your-api-key'
})
subscriber_id=111222group_id=1234567response=client.subscribers.assign_subscriber_to_group(subscriber_id, group_id)importmailerliteasMailerLiteclient=MailerLite.Client({
'api_key': 'your-api-key'
})
subscriber_id=111222group_id=1234567response=client.subscribers.unassign_subscriber_from_group(subscriber_id, group_id)importmailerliteasMailerLiteclient=MailerLite.Client({
'api_key': 'your-api-key'
})
response=client.segments.list(limit=10, page=1)importmailerliteasMailerLiteclient=MailerLite.Client({
'api_key': 'your-api-key'
})
segment_id=123456name="My New Segment Name"response=client.segments.update(segment_id, name)importmailerliteasMailerLiteclient=MailerLite.Client({
'api_key': 'your-api-key'
})
segment_id=123456response=client.segments.delete(segment_id)importmailerliteasMailerLiteclient=MailerLite.Client({
'api_key': 'your-api-key'
})
segment_id=123456response=client.segments.get_subscribers(segment_id, limit=10, filter={'status': 'active'})importmailerliteasMailerLiteclient=MailerLite.Client({
'api_key': 'your-api-key'
})
response=client.fields.list(limit=10, page=1, sort='name', filter={'keyword': 'abc', 'type': 'text'})importmailerliteasMailerLiteclient=MailerLite.Client({
'api_key': 'your-api-key'
})
name='My Field'type= 'textresponse=client.fields.create(name, type)importmailerliteasMailerLiteclient=MailerLite.Client({
'api_key': 'your-api-key'
})
field_id=123456name='My New Field'response=client.fields.update(field_id, name)importmailerliteasMailerLiteclient=MailerLite.Client({
'api_key': 'your-api-key'
})
field_id=123456response=client.fields.delete(field_id)importmailerliteasMailerLiteclient=MailerLite.Client({
'api_key': 'your-api-key'
})
response=client.automations.list(limit=10, page=1, filter={'status': true, 'name': 'some name', 'group': 123456})importmailerliteasMailerLiteclient=MailerLite.Client({
'api_key': 'your-api-key'
})
automation_id=123456response=client.automations.get(automation_id)importmailerliteasMailerLiteclient=MailerLite.Client({
'api_key': 'your-api-key'
})
automation_id=123456response=client.automations.activity(automation_id, page=1, limit=10, filter={'status': 'active', 'date_from': '2022-12-20', 'date_to': '2022-12-31'})importmailerliteasMailerLiteclient=MailerLite.Client({
'api_key': 'your-api-key'
})
response=client.campaigns.list(limit=10, page=1, filter={'status': 'ready', 'type': 'regular'})importmailerliteasMailerLiteclient=MailerLite.Client({
'api_key': 'your-api-key'
})
campaign_id=123456response=client.campaigns.get(campaign_id)importmailerliteasMailerLiteclient=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)importmailerliteasMailerLiteclient=MailerLite.Client({
'api_key': 'your-api-key'
})
campaign_id=123456params= {
"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)importmailerliteasMailerLiteclient=MailerLite.Client({
'api_key': 'your-api-key'
})
campaign_id=123456params= {
"delivery": "scheduled",
"schedule": {
"date": "2022-12-31",
"hours": "22",
"minutes": "00"
}
}
response=client.campaigns.schedule(campaign_id, params)importmailerliteasMailerLiteclient=MailerLite.Client({
'api_key': 'your-api-key'
})
campaign_id=123456response=client.campaigns.cancel(campaign_id)importmailerliteasMailerLiteclient=MailerLite.Client({
'api_key': 'your-api-key'
})
campaign_id=123456response=client.campaigns.delete(campaign_id)importmailerliteasMailerLiteclient=MailerLite.Client({
'api_key': 'your-api-key'
})
campaign_id=123456response=client.campaigns.activity(campaign_id)importmailerliteasMailerLiteclient=MailerLite.Client({
'api_key': 'your-api-key'
})
response=client.forms.list(limit=10, page=1, sort='name', filter={'name': 'form name'})importmailerliteasMailerLiteclient=MailerLite.Client({
'api_key': 'your-api-key'
})
form_id=123456response=client.forms.get(form_id)importmailerliteasMailerLiteclient=MailerLite.Client({
'api_key': 'your-api-key'
})
form_id=123456name='New Form Name'response=client.forms.update(form_id, name)importmailerliteasMailerLiteclient=MailerLite.Client({
'api_key': 'your-api-key'
})
form_id=123456response=client.forms.delete(form_id)importmailerliteasMailerLiteclient=MailerLite.Client({
'api_key': 'your-api-key'
})
form_id=123456response=client.forms.get_subscribers(form_id, page=1, limit=10, filter={'status': 'active'})importmailerliteasMailerLiteclient=MailerLite.Client({
'api_key': 'your-api-key'
})
response=client.webhooks.list()importmailerliteasMailerLiteclient=MailerLite.Client({
'api_key': 'your-api-key'
})
webhook_id=123456response=client.webhooks.get(webhook_id)importmailerliteasMailerLiteclient=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)importmailerliteasMailerLiteclient=MailerLite.Client({
'api_key': 'your-api-key'
})
webhook_id=123456events= [
'subscriber.created',
'subscriber.updated',
'subscriber.unsubscribed'
]
url='https://my-url.com'name='Webhook name'enabled=Falseresponse=client.webhooks.update(webhook_id, events, url, name, enabled)importmailerliteasMailerLiteclient=MailerLite.Client({
'api_key': 'your-api-key'
})
webhook_id=123456response=client.webhooks.delete(webhook_id)importmailerliteasMailerLiteclient=MailerLite.Client({
'api_key': 'your-api-key'
})
response=client.timezone.list()importmailerliteasMailerLiteclient=MailerLite.Client({
'api_key': 'your-api-key'
})
response=client.campaigns.languages()