> ## Documentation Index
> Fetch the complete documentation index at: https://docs.dodopayments.com/llms.txt
> Use this file to discover all available pages before exploring further.

# MailerLite

> Add paying customers to MailerLite subscriber groups and trigger MailerLite automations when Dodo Payments events such as successful payments occur.

## Introduction

The MailerLite integration adds your paying customers to MailerLite when payment events occur. It can add customers to groups, store payment data in subscriber fields, and start automation workflows, so your email lists reflect real payment activity.

MailerLite is an email marketing platform for newsletters, campaigns, and automations. Use this integration to manage subscribers based on payment activity, for onboarding sequences, customer segmentation, and targeted campaigns.

<Info>
  This integration authenticates with a MailerLite API key. To create one, open your [MailerLite Integrations page](https://dashboard.mailerlite.com/integrations/api) and click **Generate new token**.
</Info>

## Getting Started

<Steps>
  <Step title="Open the Webhook Section">
    In the Dodo Payments dashboard, go to **Developer → Webhooks** and click **Add endpoint**.

    <Frame>
      <img src="https://mintcdn.com/dodopayments/DL_ADtkdH7ph5YST/images/integrations/mailerlite.png?fit=max&auto=format&n=DL_ADtkdH7ph5YST&q=85&s=daf1cdbb629212444ad527c8dcd7adb7" alt="Add endpoint dialog with MailerLite selected in the Integration dropdown" style={{ maxHeight: '500px', width: 'auto' }} width="1536" height="1428" data-path="images/integrations/mailerlite.png" />
    </Frame>
  </Step>

  <Step title="Select MailerLite">
    In the **Integration** list, select **MailerLite**.
  </Step>

  <Step title="Enter API Key">
    Paste your MailerLite API key into the **API key** field. Dodo Payments sends it as an `Authorization` header on every delivery.
  </Step>

  <Step title="Configure Transformation">
    Edit the code under **Transformation code** so each event becomes a MailerLite subscriber request. Start from the examples below.
  </Step>

  <Step title="Test & Create">
    Under **Test this code**, run the transformation against a sample payload, then click **Create endpoint**.
  </Step>

  <Step title="Done">
    Payment events now add and update subscribers in your MailerLite groups.
  </Step>
</Steps>

## Transformation Code Examples

Most examples send a `POST` request to the MailerLite subscribers API. MailerLite creates the subscriber, or updates the existing subscriber with the same email address. This upsert never removes fields or groups that you leave out.

### Add Customer on Successful Payment

This example adds the customer to one group when a payment succeeds. Replace `your-group-id-here` with a MailerLite group ID.

```javascript add_customer.js icon="js" expandable theme={null}
function handler(webhook) {
  if (webhook.eventType === "payment.succeeded") {
    const p = webhook.payload.data;
    webhook.url = "https://connect.mailerlite.com/api/subscribers";
    webhook.payload = {
      email: p.customer.email,
      fields: {
        name: p.customer.name,
        last_name: ""
      },
      groups: ["your-group-id-here"],
      status: "active"
    };
  }
  return webhook;
}
```

### Add Subscriber to Multiple Groups Based on Product

This example adds every paying customer to a customers group, and adds customers who pay \$100 or more to a premium group as well.

```javascript product_segmentation.js icon="js" expandable theme={null}
function handler(webhook) {
  if (webhook.eventType === "payment.succeeded") {
    const p = webhook.payload.data;
    
    // Determine groups based on product or amount
    const groups = ["customers-group-id"];
    
    // Add to premium group if high-value purchase
    if (p.total_amount >= 10000) { // $100+
      groups.push("premium-customers-group-id");
    }
    
    webhook.url = "https://connect.mailerlite.com/api/subscribers";
    webhook.payload = {
      email: p.customer.email,
      fields: {
        name: p.customer.name,
        last_purchase_amount: (p.total_amount / 100).toFixed(2),
        last_purchase_date: new Date(webhook.payload.timestamp).toISOString().split('T')[0],
        payment_id: p.payment_id
      },
      groups: groups,
      status: "active"
    };
  }
  return webhook;
}
```

### Add New Subscriber on Subscription Activation

This example adds the customer to two subscriber groups and stores the plan details when a subscription becomes active.

```javascript subscription_subscriber.js icon="js" expandable theme={null}
function handler(webhook) {
  if (webhook.eventType === "subscription.active") {
    const s = webhook.payload.data;
    webhook.url = "https://connect.mailerlite.com/api/subscribers";
    webhook.payload = {
      email: s.customer.email,
      fields: {
        name: s.customer.name,
        subscription_plan: s.product_id,
        subscription_amount: (s.recurring_pre_tax_amount / 100).toFixed(2),
        billing_frequency: s.payment_frequency_interval,
        subscription_start: new Date().toISOString().split('T')[0]
      },
      groups: ["subscribers-group-id", "active-subscriptions-group-id"],
      status: "active"
    };
  }
  return webhook;
}
```

### Update Subscriber on Subscription Cancellation

This example updates an existing subscriber when a subscription is cancelled. It sends a `POST` upsert keyed by email address, because MailerLite's `PUT` update endpoint takes the MailerLite subscriber ID, which the Dodo Payments payload doesn't contain. The upsert adds the subscriber to the churned group and keeps their other groups.

```javascript subscription_cancelled.js icon="js" expandable theme={null}
function handler(webhook) {
  if (webhook.eventType === "subscription.cancelled") {
    const s = webhook.payload.data;
    // POST upserts by email; PUT needs the MailerLite subscriber ID
    webhook.url = "https://connect.mailerlite.com/api/subscribers";
    webhook.payload = {
      email: s.customer.email,
      fields: {
        subscription_status: "cancelled",
        cancellation_date: new Date().toISOString().split('T')[0]
      },
      groups: ["churned-customers-group-id"]
    };
  }
  return webhook;
}
```

### Add Customer with Custom Fields

This example stores location, contact, and payment details in subscriber fields. Create the custom fields in MailerLite first, as described in [Custom Fields Setup](#custom-fields-setup).

```javascript custom_fields.js icon="js" expandable theme={null}
function handler(webhook) {
  if (webhook.eventType === "payment.succeeded") {
    const p = webhook.payload.data;
    webhook.url = "https://connect.mailerlite.com/api/subscribers";
    webhook.payload = {
      email: p.customer.email,
      fields: {
        name: p.customer.name,
        country: p.billing?.country || "",
        city: p.billing?.city || "",
        phone: p.customer.phone_number || "",
        // Custom fields (must be created in MailerLite first)
        total_spent: (p.total_amount / 100).toFixed(2),
        customer_since: new Date().toISOString().split('T')[0],
        payment_method: p.payment_method || "unknown",
        currency: p.currency || "USD"
      },
      groups: ["paying-customers-group-id"],
      status: "active",
      subscribed_at: new Date().toISOString().replace('T', ' ').split('.')[0]
    };
  }
  return webhook;
}
```

### Trigger Automation via Event

This example updates a trigger field on every successful payment. Build an automation in MailerLite that starts when `last_payment_trigger` changes.

```javascript trigger_automation.js icon="js" expandable theme={null}
function handler(webhook) {
  if (webhook.eventType === "payment.succeeded") {
    const p = webhook.payload.data;
    
    // First, ensure subscriber exists
    webhook.url = "https://connect.mailerlite.com/api/subscribers";
    webhook.payload = {
      email: p.customer.email,
      fields: {
        name: p.customer.name,
        // Add a trigger field that your automation watches
        last_payment_trigger: new Date().toISOString(),
        last_payment_amount: (p.total_amount / 100).toFixed(2)
      },
      status: "active"
    };
    
    // Tip: Create an automation in MailerLite that triggers
    // when 'last_payment_trigger' field is updated
  }
  return webhook;
}
```

## Tips

* Create custom fields in MailerLite before you use them in a transformation.
* Use groups to segment customers by product, plan tier, or purchase behavior.
* Set up automation workflows in MailerLite that start when a field is updated.
* Send a `POST` request to `/subscribers` to upsert, which avoids duplicate subscriber errors.
* Store payment metadata in custom fields to learn more about your customers.
* Test with a small group before you enable the integration for all payments.

## Custom Fields Setup

Create each custom field in MailerLite before a transformation writes to it:

1. Open your MailerLite dashboard.
2. Go to **Subscribers → Fields**.
3. Click **Create field** and add fields such as:
   * `total_spent` (Number)
   * `customer_since` (Date)
   * `subscription_plan` (Text)
   * `payment_method` (Text)
   * `last_payment_amount` (Number)

## Troubleshooting

<AccordionGroup>
  <Accordion title="Subscribers Not Being Added">
    * Check that the API key is correct and active.
    * Check that the email address is valid under RFC 2821.
    * Check that each group ID is correct and exists in your account.
    * MailerLite doesn't reactivate bounced or junk subscribers through the API. To resubscribe a previously unsubscribed subscriber, add `resubscribe: true` to the `POST` body.
  </Accordion>

  <Accordion title="Custom Fields Not Updating">
    * Check that each custom field exists in MailerLite.
    * Check that field names match exactly. They are case-sensitive.
    * Check that each value matches the field type: text, number, or date.
  </Accordion>

  <Accordion title="Rate Limit Errors">
    * The MailerLite API allows 120 requests per minute.
    * Use the batch endpoint when you process many subscribers.
    * Add a backoff strategy for high-volume scenarios.
  </Accordion>

  <Accordion title="Group Assignment Not Working">
    * Check that group IDs are numeric strings.
    * Check that the groups exist in your MailerLite account.
    * A `PUT` request with `groups` removes the subscriber from every group it doesn't list. A `POST` request only adds groups.
  </Accordion>
</AccordionGroup>

## API Reference

The MailerLite create or upsert subscriber endpoint accepts these key parameters:

| Parameter | Type | Required | Description |
| - | - | - | - |
| `email` | string | Yes | Valid email address (RFC 2821) |
| `fields` | object | No | Object with field name/value pairs |
| `fields.name` | string | No | Subscriber's first name |
| `fields.last_name` | string | No | Subscriber's last name |
| `fields.company` | string | No | Company name |
| `fields.country` | string | No | Country |
| `fields.city` | string | No | City |
| `fields.phone` | string | No | Phone number |
| `groups` | array | No | Array of group IDs to add the subscriber to |
| `status` | string | No | One of: `active`, `unsubscribed`, `unconfirmed`, `bounced`, `junk` |
| `subscribed_at` | string | No | Date in format `yyyy-MM-dd HH:mm:ss` |
| `ip_address` | string | No | Subscriber's IP address |
| `resubscribe` | boolean | No | Set to `true` to resubscribe a previously unsubscribed subscriber |

For the complete API documentation, see [MailerLite Developers](https://developers.mailerlite.com/docs/subscribers.html).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.