MailerLite API

Welcome! You'll find comprehensive guides and documentation to help you start working with MailerLite API as quickly as possible, as well as support if you get stuck.

Let's jump right in!

Get Started    Discussions

Introduction

Webhooks provide an ability to subscribe the real-time notifications about various events occurred in MailerLite. For example, when a new subscriber is added to your account, HTTP POST callback is sent to your provided URL with a payload containing the new subscriber. It allows you to get the most recent updates without polling API constantly.

Setup

Currently, you can create subscriptions only using our RESTful API for webhooks. It is documented here.

Payload

Our responses contain fat payloads including the information about the event related object so there is no need to make additional API request.

{
  "events": [
      {
        "account_id": 334443,
        "data": {
          "subscriber": {
            "clicked": 0,
            "date_created": "2017-05-23 14:50:03",
            "date_subscribe": null,
            "date_unsubscribe": null,
            "date_updated": null,
            "email": "randomguy+wh1@mailerlite.com",
            "fields": [
              {
                "key":"email",
                "value":"randomguy+wh1@mailerlite.com",
                "type":"TEXT"
              },
              {
                "key":"name",
                "value":"Guy",
                "type":"TEXT"
              },
              {
                "key":"last_name",
                "value":"Random",
                "type":"TEXT"
              }
            ],
            "id": 2300951083,
            "name": "Guy",
            "opened": 0,
            "sent": 0,
            "type": "active"
          }
        },
        "timestamp": 1495551003,
        "type": "subscriber.create",
        "webhook_id": 2
      }
  ]
}

Available events

Event
Description

subscriber.create

Fired when a new subscriber is added to an account.

subscriber.update

Fired when any of subscriber's custom fields are updated.

subscriber.unsubscribe

Fired when a subscriber becomes unsubscribed.

subscriber.add_to_group

Fired when a subscriber is added to a group.

subscriber.remove_from_group

Fired when a subscriber is removed from a group.

Batching events

We are sending events in batches every minute. For example, if there are a few events fired and they belong to the same webhook, we group all of them and send a single HTTP request instead of many requests to the same URL.

Security

Webhook requests include X-MailerLite-Signature header, its value is base64 encoded HMAC (sha256) which is generated from payload JSON using your account's API key as a secret key. You can check its validity in order to be guaranteed that a request is sent from our side.

An example of a working function which produces a signature in PHP:

<?php

function generateSignature($jsonPayload, $apiKey) {
  return base64_encode(
    hash_hmac('sha256', $jsonPayload, $apiKey, true)
  ); 
}

Retry

If there is any other response than 2xx from your webhook's endpoint, we attempt to retry our callbacks for a while. However, your webhook is set to inactive after 3 days of responding with an error.

Unsubscribing webhooks

You can stop subscribing events for a particular webhook manually deleting it using API or just giving a response with a status code 410.

Useful tools

requestb.in is the useful tool for testing webhooks quickly and see how it is working without any coding on your side to see what's being sent.