# MailerLite

MailerLite is an email marketing platform that helps businesses create newsletters, landing pages, and automations to grow their audience. The Sling MailerLite connector extracts data from the MailerLite API v2, supporting subscribers, campaigns, groups, automations, segments, forms, custom fields, and webhooks.

{% hint style="success" %}
**CLI Pro Required**: APIs require a [CLI Pro token](https://docs.slingdata.io/sling-cli/cli-pro) or [Platform Plan](https://docs.slingdata.io/sling-platform/platform).
{% endhint %}

## Setup

The following credentials and inputs are accepted:

**Secrets:**

* `api_token` **(required)** -> Your MailerLite API token

**Inputs:**

* `anchor_date` (optional) -> Start date for initial data fetch (ISO 8601 format, e.g., `2024-01-01T00:00:00Z`). Defaults to 1 year ago.

### Getting Your API Token

1. Log in to your [MailerLite dashboard](https://dashboard.mailerlite.com/)
2. Navigate to **Integrations** from the left sidebar
3. Click **Use** on the **MailerLite API** section
4. Click **Generate new token**, give it a name (e.g., `sling-data`)
5. Accept the terms and click **Create token**
6. Copy the generated API token immediately (it won't be shown again)

### Using `sling conns`

{% code overflow="wrap" %}

```bash
sling conns set MAILERLITE type=api spec=mailerlite secrets='{ api_token: "your_api_token_here" }'
```

{% endcode %}

### Environment Variable

See [here](https://docs.slingdata.io/sling-cli/environment#dot-env-file-.env.sling) to learn more about the `.env.sling` file.

{% code overflow="wrap" %}

```bash
export MAILERLITE='{ type: api, spec: mailerlite, secrets: { api_token: "your_api_token_here" } }'
```

{% endcode %}

### Sling Env File YAML

See [here](https://docs.slingdata.io/sling-cli/environment#sling-env-file-env.yaml) to learn more about the sling `env.yaml` file.

```yaml
connections:
  MAILERLITE:
    type: api
    spec: mailerlite
    secrets:
      api_token: "your_api_token_here"
```

## Replication

Here's an example replication configuration to sync MailerLite data to a PostgreSQL database:

```yaml
source: MAILERLITE
target: MY_POSTGRES

defaults:
  mode: full-refresh
  object: mailerlite.{stream_name}

streams:
  # Core subscriber data
  subscribers:
    mode: incremental
    primary_key: [id]
    update_key: updated_at
  groups:
  group_subscribers:

  # Campaign data
  campaigns:
    mode: incremental
    primary_key: [id]
    update_key: updated_at

  # Automations and segments
  automations:
  segments:

  # Forms
  forms_popup:
  forms_embedded:
  forms_promotion:

  # Reference data
  fields:
  webhooks:
  timezones:
```

**Incremental sync example:**

```yaml
source: MAILERLITE
target: MY_POSTGRES

defaults:
  mode: incremental
  object: mailerlite.{stream_name}

streams:
  subscribers:
    primary_key: [id]
    update_key: updated_at
  campaigns:
    primary_key: [id]
    update_key: updated_at
```

**Full refresh example:**

```yaml
source: MAILERLITE
target: MY_POSTGRES

defaults:
  mode: full-refresh
  object: mailerlite.{stream_name}

streams:
  groups:
  fields:
  timezones:
  automations:
  segments:
```

## Endpoints

### Subscribers

| Endpoint            | Description                                 | Incremental |
| ------------------- | ------------------------------------------- | ----------- |
| `subscribers`       | All subscribers                             | Yes         |
| `groups`            | Subscriber groups                           | No          |
| `group_subscribers` | Subscribers in each group (child of groups) | No          |

### Campaigns

| Endpoint    | Description   | Incremental |
| ----------- | ------------- | ----------- |
| `campaigns` | All campaigns | Yes         |

### Automation & Segmentation

| Endpoint      | Description          | Incremental |
| ------------- | -------------------- | ----------- |
| `automations` | Automation workflows | No          |
| `segments`    | Subscriber segments  | No          |

### Forms

| Endpoint          | Description     | Incremental |
| ----------------- | --------------- | ----------- |
| `forms_popup`     | Popup forms     | No          |
| `forms_embedded`  | Embedded forms  | No          |
| `forms_promotion` | Promotion forms | No          |

### Reference Data

| Endpoint    | Description              | Incremental |
| ----------- | ------------------------ | ----------- |
| `fields`    | Custom subscriber fields | No          |
| `webhooks`  | Configured webhooks      | No          |
| `timezones` | Available timezones      | No          |

To discover available endpoints:

```bash
sling conns discover MAILERLITE
```

## Parent-Child Endpoints

The `group_subscribers` endpoint is a child of the `groups` endpoint and requires `groups` to run first. It iterates through each group to fetch its subscribers.

## Incremental Sync

The MailerLite connector supports time-based incremental sync for the following endpoints:

* **subscribers** - Syncs new/modified subscribers by `updated_at`
* **campaigns** - Syncs new/modified campaigns by `updated_at`

### How it works

* **First run:** Fetches all records from the anchor date (defaults to 1 year ago)
* **Subsequent runs:** Only fetches records created or modified after the last sync timestamp
* **Anchor date:** You can customize the initial lookback period by setting the `anchor_date` input

## Rate Limiting

The MailerLite API has a rate limit of 120 requests per minute.

The connector automatically:

* Uses conservative rate limiting (2 requests/second)
* Limits concurrency to 3 parallel requests
* Retries with exponential backoff on 429 (rate limit) responses

## Common Use Cases

### Sync Subscriber and Group Data

```yaml
source: MAILERLITE
target: MY_POSTGRES

defaults:
  mode: full-refresh
  object: subscribers.{stream_name}

streams:
  subscribers:
    mode: incremental
    primary_key: [id]
    update_key: updated_at
  groups:
  group_subscribers:
  fields:
```

### Sync Campaign Analytics

```yaml
source: MAILERLITE
target: MY_POSTGRES

defaults:
  mode: full-refresh
  object: campaigns.{stream_name}

streams:
  campaigns:
    mode: incremental
    primary_key: [id]
    update_key: updated_at
```

### Sync All MailerLite Data

```yaml
source: MAILERLITE
target: MY_POSTGRES

defaults:
  mode: full-refresh
  object: mailerlite.{stream_name}

streams:
  '*':
```

If you are facing issues connecting, please reach out to us at <support@slingdata.io>, on [discord](https://discord.gg/q5xtaSNDvp) or open a Github Issue [here](https://github.com/slingdata-io/sling-cli/issues).


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.slingdata.io/connections/api-connections/mailerlite.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
