# Campaigns
### Campaign list
[Official Documentation](https://developers.mailerlite.com/docs/campaigns.html#campaign-list)
---
```javascript
const params = {
filter: {
status: "sent", // possible statuses: sent, draft, ready
type: "regular" // possible types: regular, ab, resend, rss
},
limit: 25,
page: 1
};
mailerlite.campaigns.get(params)
.then(response => {
console.log(response.data);
})
.catch(error => {
if (error.response) console.log(error.response.data);
});
```
### Get a campaign
[Official Documentation](https://developers.mailerlite.com/docs/campaigns.html#get-a-campaign)
---
```javascript
mailerlite.campaigns.find("CAMPAIGN_ID")
.then(response => {
console.log(response.data);
})
.catch(error => {
if (error.response) console.log(error.response.data);
});
```
### Create a campaign
[Official Documentation](https://developers.mailerlite.com/docs/campaigns.html#create-a-campaign)
---
```javascript
const params = {
name: "Dummy AB campaign",
language_id: 4,
type: "ab",
emails: [{
subject: "Dummy subject",
from_name: "Dummy Testerson",
from: "dummy@mailerlite.io",
content: "\n\n
\n \n \n \n \n \n \n \n Untitled\n \n \n\n\n\n\n\n\n",
}],
groups: ['4243829086487936'],
ab_settings: {
test_type: "subject",
select_winner_by: "o",
after_time_amount: 2,
after_time_unit: "d",
test_split: 5,
b_value: {
subject: "Dummy subject AB test",
from_name: "Dummy Testerson AB test",
from: "dummy@mailerlite.io"
}
}
}
mailerlite.campaigns.create(params)
.then(response => {
console.log(response.data);
})
.catch(error => {
if (error.response) console.log(error.response.data);
});
```
#### Create a campaign with the simple editor
Set `editor: "simple"` on every email and omit `content` to create the email in the simple editor. The email starts blank and is then edited with the emails module. Every email in the campaign must use the same `editor`. `editor` can't be changed after the campaign is created.
```javascript
const params = {
name: "Dummy simple editor campaign",
type: "regular",
emails: [{
subject: "Dummy subject",
from_name: "Dummy Testerson",
from: "dummy@mailerlite.io",
editor: "simple"
}],
groups: ['4243829086487936']
}
mailerlite.campaigns.create(params)
.then(response => {
console.log(response.data.data.emails[0].id); // ID of the email to edit
})
.catch(error => {
if (error.response) console.log(error.response.data);
});
```
Advanced: to start from a shared gallery simple editor template instead of a blank email, also set `template_id` (a string) on every email. Own templates and other template types are rejected.
### Update campaign
[Official Documentation](https://developers.mailerlite.com/docs/campaigns.html#update-campaign)
---
```javascript
const params = {
name: "Dummy resend campaign update",
language_id: 4,
type: "resend",
emails: [{
subject: "Dummy subject update",
from_name: "Dummy Testerson update",
from: "dummy@mailerlite.io",
content: "\n\n\n \n \n \n \n \n \n \n Untitled\n \n \n\n\n\n\n\n\n",
}],
groups: ['4243829086487936'],
resend_settings: {
test_type: "subject",
select_winner_by: "o",
b_value: {
subject: "Dummy subject resend",
}
}
};
mailerlite.campaigns.update("CAMPAIGN_ID", params)
.then(response => {
console.log(response.data);
})
.catch(error => {
if (error.response) console.log(error.response.data);
});
```
### Schedule a campaign
[Official Documentation](https://developers.mailerlite.com/docs/campaigns.html#schedule-a-campaign)
---
```javascript
const params = {
delivery: "scheduled",
schedule: {
date: "2022-12-12",
hours: "12",
minutes: "12",
timezone_id: 50
}
};
mailerlite.campaigns.schedule("CAMPAIGN_ID", params)
.then(response => {
console.log(response.data);
})
.catch(error => {
if (error.response) console.log(error.response.data);
});
```
### Cancel a ready campaign
[Official Documentation](https://developers.mailerlite.com/docs/campaigns.html#cancel-a-ready-campaign)
---
```javascript
mailerlite.campaigns.cancel("CAMPAIGN_ID")
.then(response => {
console.log(response.data);
})
.catch(error => {
if (error.response) console.log(error.response.data);
});
```
### Delete a campaign
[Official Documentation](https://developers.mailerlite.com/docs/campaigns.html#delete-a-campaign)
---
```javascript
mailerlite.campaigns.delete("CAMPAIGN_ID")
.then(response => {
console.log(response.data);
})
.catch(error => {
if (error.response) console.log(error.response.data);
});
```