Basic integrations

Create a connection between your selected service and MailerLite.

We are always open to new integrations with other viable products using our API. If you have created one or are interested in creating an integration, feel free to share it with us by this dedicated contact formopen in new window.

Getting started

Before we begin, please familiarize yourself with the general API conventions, limits, and terms of service. Our API is extremely intuitive, so understanding how it works shouldn't take long if you've used a RESTful HTTP API before.

You will also need to authenticate your requests to our API. You can find out how to do that here.

For the purposes of this guide, we’ll use the example of a virtual book club. We want to integrate our custom website with our account on MailerLite.

Syncing subscribers

Let's say our clients can select "Get weekly newsletter" when signing up for a website membership.

Once the client signs up and confirms their email address, we can sync them to MailerLite using POST /api/subscribers endpoint.

Request:

POST connect.mailerlite.com/api/subscribers
1
{
    "email": "john@example.com",
    "fields": {
      "name": "John",
      "last_name": "Wick"
    }
}
1
2
3
4
5
6
7

Response:

{
  "data": {
    "id": "31897397363737859",
    "email": "john@example.com",
    "status": "active",
    "source": "api",
    "sent": 0,
    "opens_count": 0,
    "clicks_count": 0,
    "open_rate": 0,
    "click_rate": 0,
    "ip_address": null,
    "subscribed_at": "2021-08-31 14:22:08",
    "unsubscribed_at": null,
    "created_at": "2021-08-31 14:22:08",
    "updated_at": "2021-08-31 14:22:08",
    "fields": {
      "city": null,
      "company": null,
      "country": null,
      "last_name": "Wick",
      "name": "John",
      "phone": null,
      "state": null,
      "z_i_p": null
    },
    "groups": [],
    "opted_in_at": null,
    "optin_ip": null
  }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31

Pro tip: it can be a good idea to store the MailerLite subscriber id (in this case 31897397363737859) as an attribute of the client in your system. This will make further API calls much easier.

If the subscriber already exists in your mailing list, they will be updated with the newest field values.

If we want to let our clients select specific interests, we can use separate checkboxes for "True crime", "Romance", "Biographies" etc. and add them to groups accordingly.

Request:

{
    "email": "john@example.com",
    "fields": {
      "name": "John",
      "last_name": "Wick"
    },
    "groups": [
        "4243829086487936", // ID for True crime group
        "14133878422767533" // ID for Romance group
    ]
}
1
2
3
4
5
6
7
8
9
10
11

You can find the group ids listed hereopen in new window and use them as constants in your implementation.

Alternatively, you can fetch groups interactively from GET /api/groups endpoint and optionally provide a filter[name] parameter to search groups by name.

Request:

GET connect.mailerlite.com/api/groups?filter[name]=Romance
1

Response:

{
  "data": [
    {
      "id": "14133878422767533",
      "name": "Romance",
      "active_count": 256,
      "sent_count": 124,
      "opens_count": 62,
      "open_rate": {
        "float": 0.5,
        "string": "50%"
      },
      "clicks_count": 62,
      "click_rate": {
        "float": 0.5,
        "string": "50%"
      },
      "unsubscribed_count": 0,
      "unconfirmed_count": 0,
      "bounced_count": 0,
      "junk_count": 0,
      "created_at": "2022-05-24 11:52:55"
    }
  ],
  "meta": {
    "current_page": 1,
    "from": 1,
    "last_page": 1,
    "links": [
      {
        "url": null,
        "label": "« Previous",
        "active": false
      },
      {
        "url": "https://connect.mailerlite.com/api/groups?page=1",
        "label": "1",
        "active": true
      },
      {
        "url": null,
        "label": "Next »",
        "active": false
      }
    ],
    "path": "https://connect.mailerlite.com/api/groups",
    "per_page": 100,
    "to": 1,
    "total": 1
  }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51

Removing subscribers from groups

Suppose our client went into their profile and unchecked the checkbox for "Romance recommendations". We need to respect their choice and remove the subscriber from the group. If you followed advice and stored subscriber id as a client attribute, this will be super simple.

Request:

DELETE https://connect.mailerlite.com/api/subscribers/31897397363737859/groups/14133878422767533
1

Response:

Response Code: 204 No Content
1

If you didn't follow the advice and don't have the subscriber id at hand (you rebel!), you could provide an email address instead.

Request:

DELETE https://connect.mailerlite.com/api/subscribers/john@example.com/groups/14133878422767533
1

Response:

Response Code: 204 No Content
1

Mind you, this is not recommended, as subscribers can change their email address through subscriber preference centeropen in new window and thus use a different email address from your records. Only use this in a pinch.

Adding subscribers to groups

Suppose the opposite happens and the client chooses to receive "Romance recommendations" after they've already signed up.

Request:

POST https://connect.mailerlite.com/api/subscribers/31897397363737859/groups/14133878422767533
1

Response:

Response Code: 204 No Content
1

Remove subscribers

Let's say our client deleted their profile in our book club and requested to be removed from all mailing lists completely. It's not pleasant to say goodbye, but at least it's not complicated.

Request:

DELETE https://connect.mailerlite.com/api/subscribers/31897397363737859
1

Response:

Response Code: 200 Ok
1
Last Updated: